@Override public void destroyItem(ViewGroup viewPager, int position, Object object) { viewPager.removeViewAt(position); }
@Override public void showLayout(View view) { if (parentView == null) { init(); } this.currentView = view; // 如果已经是那个view,那就不需要再进行替换操作了 if (parentView.getChildAt(viewIndex) != view) { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) { parent.removeView(view); } parentView.removeViewAt(viewIndex); parentView.addView(view, viewIndex, params); } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) layout.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) lv.getParent(); // Remove ListView and add CustomView in its place int lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex); LinearLayout mLinearLayout = (LinearLayout) inflater.inflate( R.layout.custom_list, container, false); parent.addView(mLinearLayout, lvIndex, lv.getLayoutParams()); return layout; }
private static void removeContainerView(ViewGroup tipsContainerView, View targetView) { ViewGroup parent = (ViewGroup) tipsContainerView.getParent(); ViewGroup.LayoutParams targetParams = tipsContainerView.getLayoutParams(); int index = parent.indexOfChild(tipsContainerView); parent.removeViewAt(index); if (targetView.getParent() != null) { ((ViewGroup) targetView.getParent()).removeView(targetView); } parent.addView(targetView, index, targetParams); }
/** * Forces a view to duplicate its parent state, working around a bug whereby the attribute only * works if set before the view is added to its parent. */ private void setDuplicateParentState(View view) { view.setDuplicateParentStateEnabled(true); ViewGroup parent = (ViewGroup) view.getParent(); if (parent == null) { return; } int index = parent.indexOfChild(view); parent.removeViewAt(index); parent.addView(view, index); }
public void setPages(@NonNull List<EmojiconPage> pages) { this.mPages = pages; if (mTabs == null || mTabs.length != pages.size()) { mTabs = new View[pages.size()]; } else { Arrays.fill(mTabs, null); } for (int i = 0; i < mTabsContainer.getChildCount() - 2; i++) { mTabsContainer.removeViewAt(0); } int index = 0; for (EmojiconPage page : pages) { addTabIcon(page, index++); addTabDivider(); } onPageSelected(0); mViewPager.setAdapter(new EmojiconGridViewPagerAdapter(getContext(), pages)); }
@Test public void testRemoveChildAt() throws Exception { root.removeViewAt(1); assertThat(root.getChildCount()).isEqualTo(2); assertThat(root.getChildAt(0)).isSameAs(child1); assertThat(root.getChildAt(1)).isSameAs((View) child3); assertThat(child2.getParent()).isNull(); }
/** * Apply the tips view to the target view. * * @param target target view to show at. * @param tipsId tips view id. */ public View applyTo(View target, int tipsId) { mTargetView = target; ViewGroup parent = (ViewGroup) target.getParent(); if (parent == null) { return null; } View tipsView; if (parent instanceof TipsContainer) { tipsView = addTipsViewToContainer(target, parent, tipsId); } else { TipsContainer tipsContainerView = new TipsContainer(target.getContext()); ViewGroup.LayoutParams targetParams = target.getLayoutParams(); int index = parent.indexOfChild(target); parent.removeViewAt(index); parent.addView(tipsContainerView, index, targetParams); Drawable background = target.getBackground(); if (background != null) { tipsContainerView.setBackgroundDrawable(background); } tipsView = addTipsViewToContainer(target, tipsContainerView, tipsId); } return tipsView; }
@Test public void removeViewAt_shouldRequestLayout() throws Exception { View view = new View(context); ViewGroup viewGroup = new FrameLayout(context); viewGroup.addView(view); shadowOf(viewGroup).setDidRequestLayout(false); viewGroup.removeViewAt(0); assertThat(shadowOf(viewGroup).didRequestLayout()).isTrue(); }
private void init() { dayPickerView = new SimpleDayPickerView(getContext(), controller); addView(dayPickerView); final LayoutInflater inflater = LayoutInflater.from(getContext()); final ViewGroup content = (ViewGroup) inflater.inflate(R.layout.mdtp_daypicker_group, this, false); // Transfer all children from the content to this while (content.getChildCount() > 0) { final View view = content.getChildAt(0); content.removeViewAt(0); addView(view); } prevButton = findViewById(R.id.mdtp_previous_month_arrow); nextButton = findViewById(R.id.mdtp_next_month_arrow); if (controller.getVersion() == DatePickerDialog.Version.VERSION_1) { int size = Utils.dpToPx(16f, getResources()); prevButton.setMinimumHeight(size); prevButton.setMinimumWidth(size); nextButton.setMinimumHeight(size); nextButton.setMinimumWidth(size); } if (controller.isThemeDark()) { int color = ContextCompat.getColor(getContext(), R.color.mdtp_date_picker_text_normal_dark_theme); prevButton.setColorFilter(color); nextButton.setColorFilter(color); } prevButton.setOnClickListener(this); nextButton.setOnClickListener(this); dayPickerView.setOnPageListener(this); }
@Override public void onItemRangeRemoved(ObservableList observableList, int start, int count) { if (mLayoutId == 0) { return; } startTransition(mTarget); for (int i = 0; i < count; i++) { mTarget.removeViewAt(start); } } }
@Override public void onItemRangeMoved(ObservableList observableList, int from, int to, int count) { if (mLayoutId == 0) { return; } startTransition(mTarget); for (int i = 0; i < count; i++) { View view = mTarget.getChildAt(from); mTarget.removeViewAt(from); int destination = (from > to) ? to + i : to; mTarget.addView(view, destination); } }
/** * Sets the view that will always be visible and expandable. The height of your provided view will * determine the height of the entire {@link DropDownView} in collapsed mode * (only if you set <code>wrap_content</code> to the {@link DropDownView}). * * @param headerView your header view */ public void setHeaderView(@NonNull View headerView) { this.headerView = headerView; if (dropDownHeaderContainer.getChildCount() > DROP_DOWN_HEADER_CONTAINER_MIN_DEFAULT_VIEWS) { for (int i = DROP_DOWN_HEADER_CONTAINER_MIN_DEFAULT_VIEWS; i < dropDownHeaderContainer.getChildCount(); i++) { dropDownHeaderContainer.removeViewAt(i); } } dropDownHeaderContainer.addView(headerView); }
private void cleanup() { int childCount = mParentView.getChildCount(); for(int i = childCount; i >= 0; i--){ if(mParentView.getChildAt(i) instanceof LoadToastView){ LoadToastView ltv = (LoadToastView) mParentView.getChildAt(i); ltv.cleanup(); mParentView.removeViewAt(i); } } mInflated = false; mToastCanceled = false; }
/** * Removes the view, which is associated with a tab, from its parent. * * @param viewHolder * The view holder, which stores references to the tab's views, as an instance of the * class {@link PhoneTabViewHolder}. The view holder may not be null * @param tab * The tab, whose associated view should be removed, as an instance of the class {@link * Tab}. The tab may not be null */ private void removeContentView(@NonNull final PhoneTabViewHolder viewHolder, @NonNull final Tab tab) { if (viewHolder.contentContainer.getChildCount() > 2) { viewHolder.contentContainer.removeViewAt(0); } viewHolder.content = null; tabViewRecycler.remove(tab); }
@Override public void onItemRangeChanged(ObservableList observableList, int start, int count) { if (mLayoutId == 0) { return; } LayoutInflater inflater = (LayoutInflater) mTarget.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); startTransition(mTarget); final int end = start + count; for (int i = start; i < end; i++) { Object data = observableList.get(i); ViewDataBinding binding = bindLayout(inflater, mTarget, mLayoutId, data); binding.setVariable(BR.data, observableList.get(i)); mTarget.removeViewAt(i); mTarget.addView(binding.getRoot(), i); } }
@Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) layout.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) lv.getParent(); // Remove ListView and add PullToRefreshListView in its place int lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex); mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); return layout; }
decorView.removeViewAt(0);
@TargetApi(Build.VERSION_CODES.KITKAT) private static void clearPreviousSetting(Activity activity) { ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); int count = decorView.getChildCount(); if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) { decorView.removeViewAt(count - 1); ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0); rootView.setPadding(0, 0, 0, 0); } }
@TargetApi(Build.VERSION_CODES.KITKAT) private static void clearPreviousSetting(Activity activity) { ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); int count = decorView.getChildCount(); if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) { decorView.removeViewAt(count - 1); ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0); rootView.setPadding(0, 0, 0, 0); } }