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

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

源代码1 项目: mollyim-android   文件: WebRtcCallView.java
private static void setRenderer(@NonNull ViewGroup container, @Nullable View renderer) {
  if (renderer == null) {
    container.removeAllViews();
    return;
  }

  ViewParent parent = renderer.getParent();
  if (parent != null && parent != container) {
    ((ViewGroup) parent).removeAllViews();
  }

  if (parent == container) {
    return;
  }

  container.addView(renderer);
}
 
源代码2 项目: javaide   文件: ProjectManagerActivity.java
@Override
protected void initLeftNavigationView(@NonNull NavigationView nav) {
    super.initLeftNavigationView(nav);
    if (mProject == null) {
        mProject = JavaProjectManager.getLastProject(this);
    }

    String tag = FolderStructureFragment.TAG;
    FolderStructureFragment folderStructureFragment = FolderStructureFragment.newInstance(mProject);
    ViewGroup viewGroup = nav.findViewById(R.id.left_navigation_content);
    viewGroup.removeAllViews();
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.left_navigation_content, folderStructureFragment, tag).commit();
    mFilePresenter = new ProjectFilePresenter(folderStructureFragment);

}
 
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_statistics, container, false);
    ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    if (actionBar != null) {
        //actionBar.setSubtitle(R.string.action_main);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    container.removeAllViews();

    ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager);
    setupViewPager(viewPager);

    TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);

    setHasOptionsMenu(true);
    return view;
}
 
源代码4 项目: ZZShow   文件: VideoListFragment.java
/**
 * 离开此Fragment 或 不可见 时
 */
public void onDetachFromWindow(){
    if(mVideoPlayView != null){
        ViewGroup parent = (ViewGroup) mVideoPlayView.getParent();
        if(parent != null){
            parent.removeAllViews();
            if (mLastPosition <= mLayoutManager.findLastVisibleItemPosition()
                    && mLastPosition >= mLayoutManager.findFirstVisibleItemPosition()) {
                View view = mVideoListView.findViewHolderForAdapterPosition(mLastPosition).itemView;
                FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.item_layout_video);
                frameLayout.removeAllViews();
                view.findViewById(R.id.video_cover_layout).setVisibility(View.VISIBLE);
            }
        }
        mVideoPlayView.stop();
        mVideoPlayView.release();
    }
    mLastPosition = -1;
}
 
源代码5 项目: MD   文件: VideoListLayout.java
@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    if (videoLayout == null)
        return;
    if (smallLayout == null)
        return;
    if (smallLayout.getVisibility() == View.VISIBLE) {
        smallLayout.setVisibility(View.GONE);
        videoLayout.removeAllViews();
    }

    if (postion != -1) {
        ViewGroup view = (ViewGroup) videoItemView.getParent();
        if (view != null) {
            view.removeAllViews();
        }
    }
    videoItemView.stop();
    videoItemView.release();
    videoItemView.onDestroy();
    videoItemView = null;
}
 
/**
 * Clears all Views in {@code parent} and fills it with a View for
 * each item in {@code entries}, bound to the item. If layoutId
 * is 0, no Views will be added.
 *
 * @param parent The ViewGroup to contain the list of items.
 * @param layoutId The layout ID to inflate for the child Views.
 * @param entries The list of items to bind to the inflated Views. Each
 *                item will be bound to a different child View.
 */
private static void resetViews(ViewGroup parent, int layoutId,
        List entries) {
    parent.removeAllViews();
    if (layoutId == 0) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (int i = 0; i < entries.size(); i++) {
        Object entry = entries.get(i);
        ViewDataBinding binding = bindLayout(inflater, parent,
                layoutId, entry);
        parent.addView(binding.getRoot());
    }
}
 
/**
 * add your view to controller
 *
 * @param customViewType the target view type
 * @param customView     the view you want to add
 * @param removeViews    remove all views in target view before add  if true
 **/
public void addCustomView(@CustomViewType int customViewType, View customView, boolean removeViews) {
    ViewGroup viewGroup = null;
    if (customViewType == CUSTOM_VIEW_TOP && topCustomView != null) {
        viewGroup = topCustomView;
    } else if (customViewType == CUSTOM_VIEW_TOP_LANDSCAPE && topCustomView != null) {
        viewGroup = topCustomViewLandscape;
    } else if (customViewType == CUSTOM_VIEW_BOTTOM_LANDSCAPE && topCustomView != null) {
        viewGroup = bottomCustomViewLandscape;
    }

    if (viewGroup != null) {
        if (removeViews) {
            viewGroup.removeAllViews();
        }
        viewGroup.addView(customView);
    }

}
 
源代码8 项目: YImagePicker   文件: CropViewContainerHelper.java
public void refreshAllState(ImageItem currentImageItem, List<ImageItem> selectList,
                            ViewGroup invisibleContainer,
                            boolean isFitState,
                            ResetSizeExecutor executor) {
    invisibleContainer.removeAllViews();
    invisibleContainer.setVisibility(View.VISIBLE);
    for (ImageItem imageItem : selectList) {
        if (imageItem == currentImageItem) {
            continue;
        }
        CropImageView picBrowseImageView = cropViewList.get(imageItem);
        if (picBrowseImageView != null) {
            invisibleContainer.addView(picBrowseImageView);
            if (executor != null) {
                executor.resetAllCropViewSize(picBrowseImageView);
            }
            if (isFitState) {
                imageItem.setCropMode(ImageCropMode.ImageScale_FILL);
                picBrowseImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            }
            cropViewList.put(imageItem, picBrowseImageView);
        }
    }
    invisibleContainer.setVisibility(View.INVISIBLE);
}
 
源代码9 项目: Jockey   文件: LibraryActivity.java
@Override
protected void onCreateLayout(@Nullable Bundle savedInstanceState) {
    super.onCreateLayout(savedInstanceState);
    ViewGroup contentViewContainer = findViewById(android.R.id.content);
    View root = contentViewContainer.getChildAt(0);
    contentViewContainer.removeAllViews();

    mBinding = DataBindingUtil.setContentView(this, R.layout.activity_library);
    ViewGroup contentContainer = findViewById(R.id.library_content_container);
    contentContainer.addView(root);

    mBinding.libraryDrawerNavigationView.setNavigationItemSelectedListener(item -> {
        mBinding.libraryDrawerLayout.closeDrawers();
        onNavigationItemSelected(item.getItemId());
        return true;
    });
}
 
源代码10 项目: white-label-event-app   文件: HomeFragment.java
private void updateHappeningNowCard() {
    ViewGroup time_groups = (ViewGroup) cardHappeningNow.findViewById(R.id.vg_time_groups);
    time_groups.removeAllViews();

    final SortedMap<DateRange, List<AgendaItem>> happening =
        AgendaItems.happeningNow(agenda.getItems().values(), timeAtUpdate);

    if (happening.size() > 0) {
        populateTimeGroups(happening, time_groups);
        cardHappeningNow.setVisibility(View.VISIBLE);
        happeningNowStartTime = happening.firstKey().start;
    }
    else {
        cardHappeningNow.setVisibility(View.GONE);
    }
}
 
源代码11 项目: Simpler   文件: WebViewActivity.java
@Override
protected void onDestroy() {
    // 解决android webview ZoomButtonsController 导致android.view.WindowLeaked
    ViewGroup view = (ViewGroup) getWindow().getDecorView();
    view.removeAllViews();
    super.onDestroy();
}
 
源代码12 项目: flowless   文件: BasicDispatcher.java
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) {
    Log.d("BasicDispatcher", "dispatching " + traversal);
    Object dest = traversal.destination.top();

    ViewGroup frame = (ViewGroup) activity.findViewById(R.id.basic_activity_frame);

    if(traversal.origin != null) {
        if(frame.getChildCount() > 0) {
            traversal.getState(traversal.origin.top()).save(frame.getChildAt(0));
            frame.removeAllViews();
        }
    }

    @LayoutRes final int layout;
    if(dest instanceof HelloScreen) {
        layout = R.layout.hello_screen;
    } else if(dest instanceof WelcomeScreen) {
        layout = R.layout.welcome_screen;
    } else {
        throw new AssertionError("Unrecognized screen " + dest);
    }

    View incomingView = LayoutInflater.from(traversal.createContext(dest, activity)) //
            .inflate(layout, frame, false);

    frame.addView(incomingView);
    traversal.getState(traversal.destination.top()).restore(incomingView);

    callback.onTraversalCompleted();
}
 
private void createBoardUI() {
    if (mBoard != null) {
        final ViewGroup canvasView = mBoardContentView;

        canvasView.removeAllViews();

        final int kLedSize = (int) MetricsUtils.convertDpToPixel(this, kLedPixelSize);
        final int canvasViewWidth = canvasView.getWidth();
        final int canvasViewHeight = canvasView.getHeight();
        final int boardWidth = mBoard.width * kLedSize;
        final int boardHeight = mBoard.height * kLedSize;

        final int marginLeft = (canvasViewWidth - boardWidth) / 2;
        final int marginTop = (canvasViewHeight - boardHeight) / 2;

        for (int j = 0, k = 0; j < mBoard.height; j++) {
            for (int i = 0; i < mBoard.width; i++, k++) {
                View ledView = LayoutInflater.from(this).inflate(R.layout.layout_neopixel_led, canvasView, false);
                Button ledButton = (Button) ledView.findViewById(R.id.ledButton);
                RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(kLedSize, kLedSize);
                layoutParams.leftMargin = i * kLedSize + marginLeft;//mBoardMargin.left;
                layoutParams.topMargin = j * kLedSize + marginTop;//mBoardMargin.top;
                ledView.setLayoutParams(layoutParams);
                ledButton.setTag(k);

                setViewBackgroundColor(ledButton, kDefaultLedColor);
                canvasView.addView(ledView);
            }
        }



        // Setup initial scroll and scale
        resetScaleAndPanning();
    }
}
 
源代码14 项目: Roid-Library   文件: MenuDrawer.java
/**
 * Attaches the menu drawer to the window.
 */
private static void attachToDecor(Activity activity, MenuDrawer menuDrawer) {
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decorView.getChildAt(0);

    decorView.removeAllViews();
    decorView.addView(menuDrawer, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    menuDrawer.mContentContainer.addView(decorChild, decorChild.getLayoutParams());
}
 
源代码15 项目: Lucid-Browser   文件: SeekBarPreference.java
@Override
public void onBindView(View view) {
    super.onBindView(view);

    try {
        // move our seekbar to the new view we've been given
        ViewParent oldContainer = mSeekBar.getParent();
        ViewGroup newContainer = (ViewGroup) view.findViewById(R.id.seekBarPrefBarContainer);
        
        if (oldContainer != newContainer) {
            // remove the seekbar from the old view
            if (oldContainer != null) {
                ((ViewGroup) oldContainer).removeView(mSeekBar);
            }
            // remove the existing seekbar (there may not be one) and add ours
            newContainer.removeAllViews();
            newContainer.addView(mSeekBar, ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
        }
    }
    catch(Exception ex) {
        Log.e(TAG, "Error binding view: " + ex.toString());
    }
    
    //if dependency is false from the beginning, disable the seek bar
    if (view != null && !view.isEnabled())
    {
        mSeekBar.setEnabled(false);
    }
    
    updateView(view);
}
 
源代码16 项目: ZZShow   文件: VideoFragment.java
/**
 *  切换到横屏时操作
 * @return
 */
public void updateOrientationLandscape(){
    //将 VideoView 重竖屏移除
    ViewGroup viewGroup = (ViewGroup) mVideoPlayerView.getParent();
    if(viewGroup != null) {
        viewGroup.removeAllViews();
        mListener.onVideoFI(2,mVideoPlayerView);
    }
}
 
源代码17 项目: ZZShow   文件: VideoFragment.java
@Override
public void onDestroyView() {
    super.onDestroyView();
    if (mVideoPlayerView != null) {
        ViewGroup view = (ViewGroup) mVideoPlayerView.getParent();
        if (view != null) {
            view.removeAllViews();
        }
        mVideoPlayerView.stop();
        mVideoPlayerView.release();
        mVideoPlayerView.onDestory();
        mVideoPlayerView = null;
    }
}
 
public void initView(ViewGroup view) {

        if (view == null) {
            showErrorLog("initView ViewGroup can't be NULL");
            return;
        }

        context = view.getContext();

        view.removeAllViews();
        view.addView(LayoutInflater.from(view.getContext()).inflate(R.layout.record_view, null));

        timeFormatter = new SimpleDateFormat("m:ss", Locale.getDefault());

        DisplayMetrics displayMetrics = view.getContext().getResources().getDisplayMetrics();
        screenHeight = displayMetrics.heightPixels;
        screenWidth = displayMetrics.widthPixels;

        isLayoutDirectionRightToLeft = view.getContext().getResources().getBoolean(R.bool.is_right_to_left);

        viewContainer = view.findViewById(R.id.layoutContainer);
        layoutAttachmentOptions = view.findViewById(R.id.layoutAttachmentOptions);

        imageViewAttachment = view.findViewById(R.id.imageViewAttachment);
        imageViewCamera = view.findViewById(R.id.imageViewCamera);
        imageViewEmoji = view.findViewById(R.id.imageViewEmoji);
        editTextMessage = view.findViewById(R.id.editTextMessage);

        send = view.findViewById(R.id.imageSend);
        stop = view.findViewById(R.id.imageStop);
        audio = view.findViewById(R.id.imageAudio);

        imageViewAudio = view.findViewById(R.id.imageViewAudio);
        imageViewStop = view.findViewById(R.id.imageViewStop);
        imageViewSend = view.findViewById(R.id.imageViewSend);
        imageViewLock = view.findViewById(R.id.imageViewLock);
        imageViewLockArrow = view.findViewById(R.id.imageViewLockArrow);
        layoutDustin = view.findViewById(R.id.layoutDustin);
        layoutMessage = view.findViewById(R.id.layoutMessage);
        layoutAttachment = view.findViewById(R.id.layoutAttachment);
        textViewSlide = view.findViewById(R.id.textViewSlide);
        timeText = view.findViewById(R.id.textViewTime);
        layoutSlideCancel = view.findViewById(R.id.layoutSlideCancel);
        layoutEffect2 = view.findViewById(R.id.layoutEffect2);
        layoutEffect1 = view.findViewById(R.id.layoutEffect1);
        layoutLock = view.findViewById(R.id.layoutLock);
        imageViewMic = view.findViewById(R.id.imageViewMic);
        dustin = view.findViewById(R.id.dustin);
        dustin_cover = view.findViewById(R.id.dustin_cover);

        handler = new Handler(Looper.getMainLooper());

        dp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, view.getContext().getResources().getDisplayMetrics());

        animBlink = AnimationUtils.loadAnimation(view.getContext(),
                R.anim.blink);
        animJump = AnimationUtils.loadAnimation(view.getContext(),
                R.anim.jump);
        animJumpFast = AnimationUtils.loadAnimation(view.getContext(),
                R.anim.jump_fast);

        setupRecording();
        setupAttachmentOptions();
    }
 
源代码19 项目: 365browser   文件: EditorDialog.java
/**
 * Create the visual representation of the EditorModel.
 *
 * This would be more optimal as a RelativeLayout, but because it's dynamically generated, it's
 * much more human-parsable with inefficient LinearLayouts for half-width controls sharing rows.
 */
private void prepareEditor() {
    // Ensure the layout is empty.
    removeTextChangedListenersAndInputFilters();
    mDataView = (ViewGroup) mLayout.findViewById(R.id.contents);
    mDataView.removeAllViews();
    mFieldViews.clear();
    mEditableTextFields.clear();
    mDropdownFields.clear();

    // Add Views for each of the {@link EditorFields}.
    for (int i = 0; i < mEditorModel.getFields().size(); i++) {
        EditorFieldModel fieldModel = mEditorModel.getFields().get(i);
        EditorFieldModel nextFieldModel = null;

        boolean isLastField = i == mEditorModel.getFields().size() - 1;
        boolean useFullLine = fieldModel.isFullLine();
        if (!isLastField && !useFullLine) {
            // If the next field isn't full, stretch it out.
            nextFieldModel = mEditorModel.getFields().get(i + 1);
            if (nextFieldModel.isFullLine()) useFullLine = true;
        }

        if (useFullLine || isLastField) {
            addFieldViewToEditor(mDataView, fieldModel);
        } else {
            // Create a LinearLayout to put it and the next view side by side.
            LinearLayout rowLayout = new LinearLayout(mContext);
            mDataView.addView(rowLayout);

            View firstView = addFieldViewToEditor(rowLayout, fieldModel);
            View lastView = addFieldViewToEditor(rowLayout, nextFieldModel);

            LinearLayout.LayoutParams firstParams =
                    (LinearLayout.LayoutParams) firstView.getLayoutParams();
            LinearLayout.LayoutParams lastParams =
                    (LinearLayout.LayoutParams) lastView.getLayoutParams();

            firstParams.width = 0;
            firstParams.weight = 1;
            ApiCompatibilityUtils.setMarginEnd(firstParams, mHalfRowMargin);
            lastParams.width = 0;
            lastParams.weight = 1;

            // Align the text field and the dropdown field.
            if ((fieldModel.isTextField() && nextFieldModel.isDropdownField())
                    || (nextFieldModel.isTextField() && fieldModel.isDropdownField())) {
                LinearLayout.LayoutParams dropdownParams =
                        fieldModel.isDropdownField() ? firstParams : lastParams;
                dropdownParams.topMargin = mDropdownTopPadding;
                dropdownParams.bottomMargin = 0;
            }

            i = i + 1;
        }
    }

    // Add the footer.
    mDataView.addView(mFooter);
}
 
源代码20 项目: flow   文件: BasicDispatcher.java
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) {
  Log.d("BasicDispatcher", "dispatching " + traversal);
  Object destKey = traversal.destination.top();

  ViewGroup frame = (ViewGroup) activity.findViewById(R.id.basic_activity_frame);

  // We're already showing something, clean it up.
  if (frame.getChildCount() > 0) {
    final View currentView = frame.getChildAt(0);

    // Save the outgoing view state.
    if (traversal.origin != null) {
      traversal.getState(traversal.origin.top()).save(currentView);
    }

    // Short circuit if we would just be showing the same view again.
    final Object currentKey = Flow.getKey(currentView);
    if (destKey.equals(currentKey)) {
      callback.onTraversalCompleted();
      return;
    }

    frame.removeAllViews();
  }

  @LayoutRes final int layout;
  if (destKey instanceof HelloScreen) {
    layout = R.layout.hello_screen;
  } else if (destKey instanceof WelcomeScreen) {
    layout = R.layout.welcome_screen;
  } else {
    throw new AssertionError("Unrecognized screen " + destKey);
  }

  View incomingView = LayoutInflater.from(traversal.createContext(destKey, activity)) //
      .inflate(layout, frame, false);

  frame.addView(incomingView);
  traversal.getState(traversal.destination.top()).restore(incomingView);

  callback.onTraversalCompleted();
}
 
 方法所在类