android.view.ViewGroup#indexOfChild ( )源码实例Demo

下面列出了android.view.ViewGroup#indexOfChild ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xposed-rimet   文件: SettingsPlugin.java
private void onHnalderSettings(Activity activity) {

        View view = activity.findViewById(ResourceUtil.getId(activity, "setting_msg_notice"));
        ViewGroup viewGroup = (ViewGroup) view.getParent();

        final int index = viewGroup.indexOfChild(view);

        SimpleItemView viewDing = new SimpleItemView(activity);
        viewDing.getNameView().setTextSize(17);
        viewDing.setName(Constant.Name.TITLE);
        viewDing.setExtend("v" + BuildConfig.VERSION_NAME);
        viewDing.setOnClickListener(v -> {
            // 打开设置
            openSettings(activity);
        });
        viewGroup.addView(viewDing, index);
    }
 
/**
 * Set the content view to an explicit view. If the content view was installed earlier,
 * the content will be replaced with a new view.
 *
 * @param view The desired content to display. Value can't be null.
 * @see #setContentView(int)
 * @see #getContentView()
 */
public void setContentView(View view) {
    ensureContent();
    if (view == null) {
        throw new IllegalArgumentException("Content view can't be null");
    }
    if (mContentContainer instanceof ViewGroup) {
        ViewGroup contentContainer = (ViewGroup) mContentContainer;
        if (mContentView == null) {
            contentContainer.addView(view);
        } else {
            int index = contentContainer.indexOfChild(mContentView);
            // replace content view
            contentContainer.removeView(mContentView);
            contentContainer.addView(view, index);
        }
        mContentView = view;
    } else {
        throw new IllegalStateException("Can't be used with a custom content view");
    }
}
 
源代码3 项目: Telegram   文件: VideoPlayer.java
@Override
public void onPlayerError(ExoPlaybackException error) {
    Throwable cause = error.getCause();
    if (textureView != null && cause instanceof SurfaceNotValidException) {
        if (player != null) {
            ViewGroup parent = (ViewGroup) textureView.getParent();
            if (parent != null) {
                int i = parent.indexOfChild(textureView);
                parent.removeView(textureView);
                parent.addView(textureView,i);
            }
            player.clearVideoTextureView(textureView);
            player.setVideoTextureView(textureView);
            if (loopingMediaSource) {
                preparePlayerLoop(videoUri, videoType, audioUri, audioType);
            } else {
                preparePlayer(videoUri, videoType);
            }
            play();
        }
    } else {
        delegate.onError(this, error);
    }
}
 
源代码4 项目: StatusView   文件: StatusView.java
/**
 * 用 StatusView 替换要使用多状态布局的 View
 */
private static StatusView init(View contentView) {
    if (contentView == null) {
        throw new RuntimeException("ContentView can not be null!");
    }
    ViewGroup parent = (ViewGroup) contentView.getParent();
    if (parent == null) {
        throw new RuntimeException("ContentView must have a parent view!");
    }
    ViewGroup.LayoutParams lp = contentView.getLayoutParams();
    int index = parent.indexOfChild(contentView);
    parent.removeView(contentView);
    StatusView statusView = new StatusView(contentView.getContext());
    statusView.addView(contentView);
    statusView.setContentView(contentView);
    parent.addView(statusView, index, lp);
    return statusView;
}
 
源代码5 项目: Telegram-FOSS   文件: VideoPlayer.java
@Override
public void onPlayerError(ExoPlaybackException error) {
    Throwable cause = error.getCause();
    if (textureView != null && cause instanceof SurfaceNotValidException) {
        if (player != null) {
            ViewGroup parent = (ViewGroup) textureView.getParent();
            if (parent != null) {
                int i = parent.indexOfChild(textureView);
                parent.removeView(textureView);
                parent.addView(textureView,i);
            }
            player.clearVideoTextureView(textureView);
            player.setVideoTextureView(textureView);
            if (loopingMediaSource) {
                preparePlayerLoop(videoUri, videoType, audioUri, audioType);
            } else {
                preparePlayer(videoUri, videoType);
            }
            play();
        }
    } else {
        delegate.onError(this, error);
    }
}
 
源代码6 项目: LoyalNativeSlider   文件: MaterialRippleLayout.java
public MaterialRippleLayout create() {
    MaterialRippleLayout layout = new MaterialRippleLayout(context);
    layout.setRippleColor(rippleColor);
    layout.setDefaultRippleAlpha((int) rippleAlpha);
    layout.setRippleDelayClick(rippleDelayClick);
    layout.setRippleDiameter((int) dpToPx(context.getResources(), rippleDiameter));
    layout.setRippleDuration(rippleDuration);
    layout.setRippleFadeDuration(rippleFadeDuration);
    layout.setRippleHover(rippleHover);
    layout.setRipplePersistent(ripplePersistent);
    layout.setRippleOverlay(rippleOverlay);
    layout.setRippleBackground(rippleBackground);
    layout.setRippleInAdapter(rippleSearchAdapter);
    layout.setRippleRoundedCorners((int) dpToPx(context.getResources(), rippleRoundedCorner));

    ViewGroup.LayoutParams params = child.getLayoutParams();
    ViewGroup parent = (ViewGroup) child.getParent();
    int index = 0;

    if (parent != null && parent instanceof MaterialRippleLayout) {
        throw new IllegalStateException("MaterialRippleLayout could not be created: parent of the view already is a MaterialRippleLayout");
    }

    if (parent != null) {
        index = parent.indexOfChild(child);
        parent.removeView(child);
    }

    layout.addView(child, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

    if (parent != null) {
        parent.addView(layout, index, params);
    }

    return layout;
}
 
源代码7 项目: react-native-navigation   文件: TestUtils.java
public static <T extends View> T spyOn(T child) {
    ViewGroup parent = (ViewGroup) child.getParent();
    int indexOf = parent.indexOfChild(child);
    parent.removeView(child);
    T spy = Mockito.spy(child);
    parent.addView(spy, indexOf);
    return spy;
}
 
源代码8 项目: a   文件: BadgeView.java
/**
 * Attach the BadgeView to the target view
 * @param target the view to attach the BadgeView
 */
public void setTargetView(View target) {
    if (getParent() != null) {
        ((ViewGroup) getParent()).removeView(this);
    }

    if (target == null) {
        return;
    }

    if (target.getParent() instanceof FrameLayout) {
        ((FrameLayout) target.getParent()).addView(this);

    } else if (target.getParent() instanceof ViewGroup) {
        // use a new Framelayout container for adding badge
        ViewGroup parentContainer = (ViewGroup) target.getParent();
        int groupIndex = parentContainer.indexOfChild(target);
        parentContainer.removeView(target);

        FrameLayout badgeContainer = new FrameLayout(getContext());
        ViewGroup.LayoutParams parentLayoutParams = target.getLayoutParams();

        badgeContainer.setLayoutParams(parentLayoutParams);
        target.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        parentContainer.addView(badgeContainer, groupIndex, parentLayoutParams);
        badgeContainer.addView(target);

        badgeContainer.addView(this);
    }

}
 
源代码9 项目: UltimateAndroid   文件: UnfoldableView.java
private void switchViews(View origin, View replacement, ViewGroup.LayoutParams params) {
    ViewGroup parent = (ViewGroup) origin.getParent();

    if (params == null) params = origin.getLayoutParams();

    int index = parent.indexOfChild(origin);
    parent.removeViewAt(index);
    parent.addView(replacement, index, params);
}
 
源代码10 项目: FamilyChat   文件: ParallaxTransformer.java
private void bringViewToFront(View view) {
    ViewGroup group = (ViewGroup) view.getParent();
    int index = group.indexOfChild(view);
    if (index != group.getChildCount() - 1) {
        view.bringToFront();
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            view.requestLayout();
            group.invalidate();
        }
    }
}
 
源代码11 项目: LRecyclerView   文件: PullScrollView.java
private void setLayout() {
    ViewGroup group = (ViewGroup) getParent();
    LinearLayout container = new LinearLayout(getContext());
    container.setOrientation(LinearLayout.VERTICAL);
    int index = group.indexOfChild(this);
    group.removeView(this);
    group.addView(container, index, getLayoutParams());

    container.addView(mRefreshHeader.getHeaderView(), new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    container.addView(this, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
 
源代码12 项目: umeng_community_android   文件: BadgeView.java
private void applyTo(View target) {

        LayoutParams lp = target.getLayoutParams();
        ViewParent parent = target.getParent();
        FrameLayout container = new FrameLayout(context);

        if (target instanceof TabWidget) {
            // set target to the relevant tab child container
            target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
            this.target = target;

            ((ViewGroup) target).addView(container,
                    new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

            this.setVisibility(View.GONE);
            container.addView(this);
        } else {
            ViewGroup group = (ViewGroup) parent;
            int index = group.indexOfChild(target);

            group.removeView(target);
            group.addView(container, index, lp);

            container.addView(target);

            this.setVisibility(View.GONE);
            container.addView(this);

            group.invalidate();

        }

    }
 
源代码13 项目: openScale   文件: MeasurementView.java
private MeasurementView getNextView() {
    ViewGroup parent = (ViewGroup) getParent();
    for (int i = parent.indexOfChild(this) + 1; i < parent.getChildCount(); ++i) {
        MeasurementView next = (MeasurementView) parent.getChildAt(i);
        if (next.isVisible() && next.isEditable()) {
            return next;
        }
    }
    return null;
}
 
源代码14 项目: fingerpoetry-android   文件: RippleLayout.java
public RippleLayout create() {
    RippleLayout layout = new RippleLayout(context);
    layout.setRippleColor(rippleColor);
    layout.setDefaultRippleAlpha((int) rippleAlpha);
    layout.setRippleDelayClick(rippleDelayClick);
    layout.setRippleDiameter((int) dpToPx(context.getResources(), rippleDiameter));
    layout.setRippleDuration(rippleDuration);
    layout.setRippleFadeDuration(rippleFadeDuration);
    layout.setRippleHover(rippleHover);
    layout.setRipplePersistent(ripplePersistent);
    layout.setRippleOverlay(rippleOverlay);
    layout.setRippleBackground(rippleBackground);
    layout.setRippleInAdapter(rippleSearchAdapter);
    layout.setRippleRoundedCorners((int) dpToPx(context.getResources(), rippleRoundedCorner));

    ViewGroup.LayoutParams params = child.getLayoutParams();
    ViewGroup parent = (ViewGroup) child.getParent();
    int index = 0;

    if (parent != null && parent instanceof RippleLayout) {
        throw new IllegalStateException("MaterialRippleLayout could not be created: parent of the view already is a MaterialRippleLayout");
    }

    if (parent != null) {
        index = parent.indexOfChild(child);
        parent.removeView(child);
    }

    layout.addView(child, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

    if (parent != null) {
        parent.addView(layout, index, params);
    }

    return layout;
}
 
@Override
public void animate() {
	final ViewGroup parentView = (ViewGroup) view.getParent();
	final FrameLayout slideOutFrame = new FrameLayout(view.getContext());
	final int positionView = parentView.indexOfChild(view);
	slideOutFrame.setLayoutParams(view.getLayoutParams());
	slideOutFrame.setClipChildren(true);
	parentView.removeView(view);
	slideOutFrame.addView(view);
	parentView.addView(slideOutFrame, positionView);

	switch (direction) {
	case DIRECTION_LEFT:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_X,
				view.getTranslationX() - view.getWidth());
		break;
	case DIRECTION_RIGHT:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_X,
				view.getTranslationX() + view.getWidth());
		break;
	case DIRECTION_UP:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y,
				view.getTranslationY() - view.getHeight());
		break;
	case DIRECTION_DOWN:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y,
				view.getTranslationY() + view.getHeight());
		break;
	default:
		break;
	}

	AnimatorSet slideSet = new AnimatorSet();
	slideSet.play(slideAnim);
	slideSet.setInterpolator(interpolator);
	slideSet.setDuration(duration);
	slideSet.addListener(new AnimatorListenerAdapter() {

		@Override
		public void onAnimationEnd(Animator animation) {
			view.setVisibility(View.INVISIBLE);
			slideAnim.reverse();
			slideOutFrame.removeAllViews();
			parentView.removeView(slideOutFrame);
			parentView.addView(view, positionView);
			if (getListener() != null) {
				getListener().onAnimationEnd(
						SlideOutUnderneathAnimation.this);
			}
		}
	});
	slideSet.start();
}
 
源代码16 项目: volume_control_android   文件: MainActivity.java
private void renderProfileItems() {
    View title = findViewById(R.id.audio_types_holder_title);
    ViewGroup titlesGroup = findViewById(R.id.linearLayout);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        titlesGroup.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
    }

    int indexOfTitle = titlesGroup.indexOfChild(title);

    List<AudioType> audioTypes = AudioType.getAudioTypes(true);

    if (!Boolean.TRUE.equals(title.getTag())) {
        for (int i = 0; i < audioTypes.size(); i++) {
            AudioType type = audioTypes.get(i);

            final VolumeSliderView volumeSliderView = new VolumeSliderView(this);

            volumeSliderView.setTag(type.audioStreamName);
            titlesGroup.addView(volumeSliderView, indexOfTitle + i + 1, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

            volumeSliderView.setVolumeName(getString(type.nameId));
            volumeSliderView.setMaxVolume(control.getMaxLevel(type.audioStreamName));
            volumeSliderView.setMinVolume(control.getMinLevel(type.audioStreamName));
            volumeSliderView.setCurrentVolume(control.getLevel(type.audioStreamName));


            final TypeListener volumeListener = new TypeListener(type.audioStreamName) {
                @Override
                public void onChangeIndex(int audioType, int currentLevel, int max) {
                    if (currentLevel < control.getMinLevel(type)) {
                        volumeSliderView.setCurrentVolume(control.getMinLevel(type));
                    } else {
                        volumeSliderView.setCurrentVolume(currentLevel);
                    }
                }
            };

            volumeListeners.add(volumeListener);

            volumeSliderView.setListener((volume, fromUser) -> {
                if (fromUser) {
                    requireChangeVolume(type, volume);
                }
            });
        }
        title.setTag(Boolean.TRUE);
    }

    for (AudioType audioExtendedType : AudioType.getAudioExtendedTypes()) {
        titlesGroup.findViewWithTag(audioExtendedType.audioStreamName).setVisibility(isExtendedVolumesEnabled() ? View.VISIBLE : View.GONE);
    }
}
 
源代码17 项目: Android-tv-widget   文件: WidgetTvViewBring.java
public void bringChildToFront(ViewGroup vg, View child) {
	position = vg.indexOfChild(child);
	if (position != -1) {
		vg.postInvalidate();
	}
}
 
源代码18 项目: Luban-Circle-Demo   文件: ViewUtils.java
public static void replaceChild(ViewGroup viewGroup, View oldChild, View newChild) {
    int index = viewGroup.indexOfChild(oldChild);
    viewGroup.removeViewAt(index);
    viewGroup.addView(newChild, index);
}
 
源代码19 项目: tysq-android   文件: BadgeView.java
private void applyTo(View target) {

        LayoutParams lp = target.getLayoutParams();
        ViewParent parent = target.getParent();
        FrameLayout container = new FrameLayout(context);

        if (target instanceof TabWidget) {

            // set target to the relevant tab child container
            target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
            this.target = target;

            ((ViewGroup) target).addView(container,
                    new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

            this.setVisibility(View.GONE);
            container.addView(this);

        } else {

            // TODO verify that parent is indeed a ViewGroup
            ViewGroup group = (ViewGroup) parent;
            int index = group.indexOfChild(target);

            group.removeView(target);
            group.addView(container, index, lp);

            container.addView(target);

            this.setVisibility(View.GONE);
            container.addView(this);

            group.invalidate();

        }

    }
 
源代码20 项目: android-common-utils   文件: BadgeView.java
private void applyTo(View target) {
	
	LayoutParams lp = target.getLayoutParams();
	ViewParent parent = target.getParent();
	FrameLayout container = new FrameLayout(context);
	
	if (target instanceof TabWidget) {
		
		// set target to the relevant tab child container
		target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
		this.target = target;
		
		((ViewGroup) target).addView(container, 
				new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		
		this.setVisibility(View.GONE);
		container.addView(this);
		
	} else {
		
		// TODO verify that parent is indeed a ViewGroup
		ViewGroup group = (ViewGroup) parent; 
		int index = group.indexOfChild(target);
		
		group.removeView(target);
		group.addView(container, index, lp);
		
		container.addView(target);

		this.setVisibility(View.GONE);
		container.addView(this);
		
		group.invalidate();
		
	}
	
}
 
 方法所在类