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

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

源代码1 项目: android_9.0.0_r45   文件: Toolbar.java
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    // If the container is a cluster, unmark itself as a cluster to avoid having nested
    // clusters.
    ViewParent parent = getParent();
    while (parent != null && parent instanceof ViewGroup) {
        final ViewGroup vgParent = (ViewGroup) parent;
        if (vgParent.isKeyboardNavigationCluster()) {
            setKeyboardNavigationCluster(false);
            if (vgParent.getTouchscreenBlocksFocus()) {
                setTouchscreenBlocksFocus(false);
            }
            break;
        }
        parent = vgParent.getParent();
    }
}
 
源代码2 项目: Awesome-WanAndroid   文件: BaseRootActivity.java
@Override
protected void initEventAndData() {
    mNormalView = (ViewGroup) findViewById(R.id.normal_view);
    if (mNormalView == null) {
        throw new IllegalStateException(
                "The subclass of RootActivity must contain a View named 'mNormalView'.");
    }
    if (!(mNormalView.getParent() instanceof ViewGroup)) {
        throw new IllegalStateException(
                "mNormalView's ParentView should be a ViewGroup.");
    }
    ViewGroup mParent = (ViewGroup) mNormalView.getParent();
    View.inflate(this, R.layout.loading_view, mParent);
    View.inflate(this, R.layout.error_view, mParent);
    mLoadingView = mParent.findViewById(R.id.loading_group);
    mErrorView = mParent.findViewById(R.id.error_group);
    TextView reloadTv = mErrorView.findViewById(R.id.error_reload_tv);
    reloadTv.setOnClickListener(v -> reload());
    mLoadingAnimation = mLoadingView.findViewById(R.id.loading_animation);
    mErrorView.setVisibility(View.GONE);
    mLoadingView.setVisibility(View.GONE);
    mNormalView.setVisibility(View.VISIBLE);
}
 
源代码3 项目: TestChat   文件: ShareMessageFragment.java
@Override
public void onCommentItemClick(View view, String id, int shareMessagePosition, int position, String replyUser) {
        LogUtil.e("位置" + shareMessagePosition);
        currentPosition = shareMessagePosition;
        currentCommentPosition = position;
        ViewParent viewParent = view.getParent();
        if (viewParent != null) {
                ViewGroup parent = (ViewGroup) viewParent;
                commentItemOffset += parent.getHeight() - view.getBottom();
                if (parent.getParent() != null) {
                        ViewGroup rootParent = (ViewGroup) parent.getParent();
                        commentItemOffset += rootParent.getHeight() + parent.getBottom();
                }
        }
        this.replyUid = replyUser;
        dealBottomView(true);
}
 
源代码4 项目: TestChat   文件: UserDetailActivity.java
@Override
public void onCommentItemClick(View view, String id, int shareMessagePosition, int commentPosition, String replyUid) {
        LogUtil.e("位置" + shareMessagePosition);
        currentPosition = shareMessagePosition;
        currentCommentPosition = commentPosition;
        ViewParent viewParent = view.getParent();
        if (viewParent != null) {
                ViewGroup parent = (ViewGroup) viewParent;
                commentItemOffset += parent.getHeight() - view.getBottom();
                if (parent.getParent() != null) {
                        ViewGroup rootParent = (ViewGroup) parent.getParent();
                        commentItemOffset += rootParent.getHeight() + parent.getBottom();
                }
        }
        this.replyUid = replyUid;
        dealBottomView(true);
}
 
源代码5 项目: LB-Launcher   文件: PagedView.java
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Hook up the page indicator
    ViewGroup parent = (ViewGroup) getParent();
    ViewGroup grandParent = (ViewGroup) parent.getParent();
    if (mPageIndicator == null && mPageIndicatorViewId > -1) {
        mPageIndicator = (PageIndicator) grandParent.findViewById(mPageIndicatorViewId);
        mPageIndicator.removeAllMarkers(mAllowPagedViewAnimations);

        ArrayList<PageIndicator.PageMarkerResources> markers =
                new ArrayList<PageIndicator.PageMarkerResources>();
        for (int i = 0; i < getChildCount(); ++i) {
            markers.add(getPageIndicatorMarker(i));
        }

        mPageIndicator.addMarkers(markers, mAllowPagedViewAnimations);

        OnClickListener listener = getPageIndicatorClickListener();
        if (listener != null) {
            mPageIndicator.setOnClickListener(listener);
        }
        mPageIndicator.setContentDescription(getPageIndicatorDescription());
    }
}
 
源代码6 项目: NewbieGuide   文件: Controller.java
/**
 * 中断引导层的显示,后续未显示的page将不再显示
 */
public void remove() {
    if (currentLayout != null && currentLayout.getParent() != null) {
        ViewGroup parent = (ViewGroup) currentLayout.getParent();
        parent.removeView(currentLayout);
        //移除anchor添加的frameLayout
        if (!(parent instanceof FrameLayout)) {
            ViewGroup original = (ViewGroup) parent.getParent();
            View anchor = parent.getChildAt(0);
            parent.removeAllViews();
            if (anchor != null) {
                if (indexOfChild > 0) {
                    original.addView(anchor, indexOfChild, parent.getLayoutParams());
                } else {
                    original.addView(anchor, parent.getLayoutParams());
                }
            }
        }
        if (onGuideChangedListener != null) {
            onGuideChangedListener.onRemoved(this);
        }
        currentLayout = null;
    }
    isShowing = false;
}
 
源代码7 项目: BoardView   文件: BoardView.java
public void notifyDataSetChanged(){
    for(int column_pos = 0; column_pos < boardAdapter.columns.size(); column_pos++) {
        if(boardAdapter.columns.get(column_pos).header != null) {
            ViewGroup parent_header = removeParent(boardAdapter.columns.get(column_pos).header);
            boardAdapter.columns.get(column_pos).header = boardAdapter.createHeaderView(getContext(), boardAdapter.columns.get(column_pos).header_object, column_pos);
            parent_header.addView(boardAdapter.columns.get(column_pos).header);
            ViewGroup layout = (ViewGroup)parent_header.getParent();
            boardAdapter.columns.get(column_pos).header.setOnClickListener(createHeaderOnClickListener(layout));
            boardAdapter.columns.get(column_pos).header.setOnLongClickListener(createHeaderOnLongClickListener(parent_header,layout));

        }
        if(boardAdapter.columns.get(column_pos).footer != null) {
            ViewGroup parent_footer = removeParent(boardAdapter.columns.get(column_pos).footer);
            boardAdapter.columns.get(column_pos).footer = boardAdapter.createFooterView(getContext(), boardAdapter.columns.get(column_pos).footer_object, column_pos);
            parent_footer.addView(boardAdapter.columns.get(column_pos).footer);
        }
    }
}
 
源代码8 项目: debugdrawer   文件: MadgeModule.java
public void attach(Activity activity, ViewGroup content){
    madgeFrameLayout = new MadgeFrameLayout(activity);

    ViewGroup parent = (ViewGroup) content.getParent();
    parent.removeView(content);
    parent.addView(madgeFrameLayout,0);
    madgeFrameLayout.addView(content);

    boolean gridEnabled = pixelGridEnabled.get();
    madgeFrameLayout.setOverlayEnabled(gridEnabled);
    uiPixelGridElement.setChecked(gridEnabled);
    uiPixelRatioElement.setEnabled(gridEnabled);

    boolean ratioEnabled = pixelRatioEnabled.get();
    madgeFrameLayout.setOverlayRatioEnabled(ratioEnabled);
    uiPixelRatioElement.setChecked(ratioEnabled);
}
 
源代码9 项目: Highlight   文件: HighLight.java
@Override
public HighLight remove() {
    if (getHightLightView() == null) return this;
    ViewGroup parent = (ViewGroup) mHightLightView.getParent();
    if (parent instanceof RelativeLayout || parent instanceof FrameLayout) {
        parent.removeView(mHightLightView);
    } else {
        parent.removeView(mHightLightView);
        View origin = parent.getChildAt(0);
        ViewGroup graParent = (ViewGroup) parent.getParent();
        graParent.removeView(parent);
        graParent.addView(origin, parent.getLayoutParams());
    }
    mHightLightView = null;

    sendRemoveMessage();
    mShowing = false;
    return this;
}
 
源代码10 项目: react-native-navigation   文件: StackController.java
public void pop(Options mergeOptions, CommandListener listener) {
    if (!canPop()) {
        listener.onError("Nothing to pop");
        return;
    }

    peek().mergeOptions(mergeOptions);
    Options disappearingOptions = resolveCurrentOptions(presenter.getDefaultOptions());

    final ViewController disappearing = stack.pop();
    final ViewController appearing = stack.peek();

    disappearing.onViewWillDisappear();
    appearing.onViewWillAppear();

    ViewGroup appearingView = appearing.getView();
    if (appearingView.getLayoutParams() == null) {
        appearingView.setLayoutParams(matchParentWithBehaviour(new StackBehaviour(this)));
    }
    if (appearingView.getParent() == null) {
        getView().addView(appearingView, 0);
    }
    presenter.onChildWillAppear(this, appearing, disappearing);
    if (disappearingOptions.animations.pop.enabled.isTrueOrUndefined()) {
        animator.pop(disappearing.getView(), disappearingOptions.animations.pop, () -> finishPopping(disappearing, listener));
    } else {
        finishPopping(disappearing, listener);
    }
}
 
源代码11 项目: GankGirl   文件: TipsUtils.java
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);
}
 
源代码12 项目: labelview   文件: LabelView.java
public void remove() {
    if (getParent() == null || _labelViewContainerID == -1) {
        return;
    }

    ViewGroup frameContainer = (ViewGroup) getParent();
    assert (frameContainer.getChildCount() == 2);
    View target = frameContainer.getChildAt(0);

    ViewGroup parentContainer = (ViewGroup) frameContainer.getParent();
    int groupIndex = parentContainer.indexOfChild(frameContainer);
    if (frameContainer.getParent() instanceof RelativeLayout) {
        for (int i = 0; i < parentContainer.getChildCount(); i++) {
            if (i == groupIndex) {
                continue;
            }
            View view = parentContainer.getChildAt(i);
            RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams();
            for (int j = 0; j < para.getRules().length; j++) {
                if (para.getRules()[j] == _labelViewContainerID) {
                    para.getRules()[j] = target.getId();
                }
            }
            view.setLayoutParams(para);
        }
    }

    ViewGroup.LayoutParams frameLayoutParam = frameContainer.getLayoutParams();
    target.setLayoutParams(frameLayoutParam);
    parentContainer.removeViewAt(groupIndex);
    frameContainer.removeView(target);
    frameContainer.removeView(this);
    parentContainer.addView(target,groupIndex);
    _labelViewContainerID = -1;
}
 
源代码13 项目: 365browser   文件: ViewAndroidDelegate.java
/**
 * @return An anchor view that can be used to anchor decoration views like Autofill popup.
 */
@CalledByNative
public View acquireView() {
    ViewGroup containerView = getContainerView();
    if (containerView == null || containerView.getParent() == null) return null;
    View anchorView = new View(containerView.getContext());
    containerView.addView(anchorView);
    return anchorView;
}
 
源代码14 项目: LB-Launcher   文件: FolderIcon.java
public boolean isDropEnabled() {
    final ViewGroup cellLayoutChildren = (ViewGroup) getParent();
    final ViewGroup cellLayout = (ViewGroup) cellLayoutChildren.getParent();
    final Workspace workspace = (Workspace) cellLayout.getParent();
    return !workspace.workspaceInModalState();
}
 
源代码15 项目: backstack   文件: LinearBackStack.java
private void removeView(BackStackNode backStackNode, ViewGroup viewGroup){
    if (!backStackNode.shouldRetain){
        ViewGroup parent = (ViewGroup) viewGroup.getParent();
        parent.removeView(viewGroup);
    }
}
 
源代码16 项目: backstack   文件: LinearBackStack.java
private void forceRemoveView(BackStackNode backStackNode, ViewGroup viewGroup){
    ViewGroup parent = (ViewGroup) viewGroup.getParent();
    parent.removeView(viewGroup);
}
 
@Override
public void setAdapter(Adapter adapter) {
    // Only once
    if (mEmptyViewResId != -1) {
        if (null != getParent()) {
            ViewGroup parentView = ((ViewGroup) getParent());
            View tempEmptyView1 = parentView.findViewById(mEmptyViewResId);

            if (null != tempEmptyView1) {
                mEmptyView = tempEmptyView1;

                if (isKeepShowHeadOrFooter) parentView.removeView(tempEmptyView1);
            } else {
                ViewParent pParentView = parentView.getParent();
                if (pParentView instanceof ViewGroup) {
                    View tempEmptyView2 = ((ViewGroup) pParentView).findViewById(mEmptyViewResId);
                    if (null != tempEmptyView2) {
                        mEmptyView = tempEmptyView2;

                        if (isKeepShowHeadOrFooter)
                            ((ViewGroup) pParentView).removeView(tempEmptyView2);
                    }
                }
            }
        }
        mEmptyViewResId = -1;
    } else if (isKeepShowHeadOrFooter && null != mEmptyView) {
        ViewParent emptyViewParent = mEmptyView.getParent();
        if (emptyViewParent instanceof ViewGroup) {
            ((ViewGroup) emptyViewParent).removeView(mEmptyView);
        }
    }

    if (null == adapter) {
        if (null != mReqAdapter) {
            if (!isKeepShowHeadOrFooter) {
                mReqAdapter.unregisterAdapterDataObserver(mReqAdapterDataObserver);
            }
            mReqAdapter = null;
            mWrapFamiliarRecyclerViewAdapter = null;

            processEmptyView();
        }

        return;
    }

    mReqAdapter = adapter;
    mWrapFamiliarRecyclerViewAdapter = new FamiliarWrapRecyclerViewAdapter(this, adapter, mHeaderView, mFooterView, mLayoutManagerType);

    mWrapFamiliarRecyclerViewAdapter.setOnItemClickListener(mTempOnItemClickListener);
    mWrapFamiliarRecyclerViewAdapter.setOnItemLongClickListener(mTempOnItemLongClickListener);
    mWrapFamiliarRecyclerViewAdapter.setOnHeadViewBindViewHolderListener(mTempOnHeadViewBindViewHolderListener);
    mWrapFamiliarRecyclerViewAdapter.setOnFooterViewBindViewHolderListener(mTempOnFooterViewBindViewHolderListener);

    mReqAdapter.registerAdapterDataObserver(mReqAdapterDataObserver);
    super.setAdapter(mWrapFamiliarRecyclerViewAdapter);

    if (needInitAddItemDescration && null != mFamiliarDefaultItemDecoration) {
        needInitAddItemDescration = false;
        super.addItemDecoration(mFamiliarDefaultItemDecoration);
    }

    processEmptyView();
}
 
源代码18 项目: android-apps   文件: ActionBarSherlockCompat.java
private ViewGroup generateLayout() {
    if (DEBUG) Log.d(TAG, "[generateLayout]");

    // Apply data from current theme.

    TypedArray a = mActivity.getTheme().obtainStyledAttributes(R.styleable.SherlockTheme);

    mIsFloating = a.getBoolean(R.styleable.SherlockTheme_android_windowIsFloating, false);

    if (!a.hasValue(R.styleable.SherlockTheme_windowActionBar)) {
        throw new IllegalStateException("You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.");
    }

    if (a.getBoolean(R.styleable.SherlockTheme_windowNoTitle, false)) {
        requestFeature(Window.FEATURE_NO_TITLE);
    } else if (a.getBoolean(R.styleable.SherlockTheme_windowActionBar, false)) {
        // Don't allow an action bar if there is no title.
        requestFeature(Window.FEATURE_ACTION_BAR);
    }

    if (a.getBoolean(R.styleable.SherlockTheme_windowActionBarOverlay, false)) {
        requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    }

    if (a.getBoolean(R.styleable.SherlockTheme_windowActionModeOverlay, false)) {
        requestFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
    }

    a.recycle();

    int layoutResource;
    if (!hasFeature(Window.FEATURE_NO_TITLE)) {
        if (mIsFloating) {
            //Trash original dialog LinearLayout
            mDecor = (ViewGroup)mDecor.getParent();
            mDecor.removeAllViews();

            layoutResource = R.layout.abs__dialog_title_holo;
        } else {
            if (hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) {
                layoutResource = R.layout.abs__screen_action_bar_overlay;
            } else {
                layoutResource = R.layout.abs__screen_action_bar;
            }
        }
    } else if (hasFeature(Window.FEATURE_ACTION_MODE_OVERLAY) && !hasFeature(Window.FEATURE_NO_TITLE)) {
        layoutResource = R.layout.abs__screen_simple_overlay_action_mode;
    } else {
        layoutResource = R.layout.abs__screen_simple;
    }

    if (DEBUG) Log.d(TAG, "[generateLayout] using screen XML " + mActivity.getResources().getString(layoutResource));
    View in = mActivity.getLayoutInflater().inflate(layoutResource, null);
    mDecor.addView(in, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

    ViewGroup contentParent = (ViewGroup)mDecor.findViewById(R.id.abs__content);
    if (contentParent == null) {
        throw new RuntimeException("Couldn't find content container view");
    }

    //Make our new child the true content view (for fragments). VERY VOLATILE!
    mDecor.setId(View.NO_ID);
    contentParent.setId(android.R.id.content);

    if (hasFeature(Window.FEATURE_INDETERMINATE_PROGRESS)) {
        IcsProgressBar progress = getCircularProgressBar(false);
        if (progress != null) {
            progress.setIndeterminate(true);
        }
    }

    return contentParent;
}
 
源代码19 项目: TurboLauncher   文件: FocusHelper.java
/**
 * Handles key events in the workspace hotseat (bottom of the screen).
 */
static boolean handleHotseatButtonKeyEvent(View v, int keyCode, KeyEvent e, int orientation) {
    final ViewGroup parent = (ViewGroup) v.getParent();
    final ViewGroup launcher = (ViewGroup) parent.getParent();
    final Workspace workspace = (Workspace) launcher.findViewById(R.id.workspace);
    final int buttonIndex = parent.indexOfChild(v);
    final int buttonCount = parent.getChildCount();
    final int pageIndex = workspace.getCurrentPage();

    // NOTE: currently we don't special case for the phone UI in different
    // orientations, even though the hotseat is on the side in landscape mode.  This
    // is to ensure that accessibility consistency is maintained across rotations.

    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    boolean wasHandled = false;
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (handleKeyEvent) {
                // Select the previous button, otherwise snap to the previous page
                if (buttonIndex > 0) {
                    parent.getChildAt(buttonIndex - 1).requestFocus();
                } else {
                    workspace.snapToPage(pageIndex - 1);
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (handleKeyEvent) {
                // Select the next button, otherwise snap to the next page
                if (buttonIndex < (buttonCount - 1)) {
                    parent.getChildAt(buttonIndex + 1).requestFocus();
                } else {
                    workspace.snapToPage(pageIndex + 1);
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (handleKeyEvent) {
                // Select the first bubble text view in the current page of the workspace
                final CellLayout layout = (CellLayout) workspace.getChildAt(pageIndex);
                final ShortcutAndWidgetContainer children = layout.getShortcutsAndWidgets();
                final View newIcon = getIconInDirection(layout, children, -1, 1);
                if (newIcon != null) {
                    newIcon.requestFocus();
                } else {
                    workspace.requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            // Do nothing
            wasHandled = true;
            break;
        default: break;
    }
    return wasHandled;
}
 
源代码20 项目: TurboLauncher   文件: FolderIcon.java
public boolean isDropEnabled() {
    final ViewGroup cellLayoutChildren = (ViewGroup) getParent();
    final ViewGroup cellLayout = (ViewGroup) cellLayoutChildren.getParent();
    final Workspace workspace = (Workspace) cellLayout.getParent();
    return !workspace.isSmall();
}
 
 方法所在类