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

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

源代码1 项目: Simple-Solitaire   文件: GameSelector.java
/**
 * Starts the clicked game. This uses the total index position of the clicked view to get the
 * game.
 *
 * @param view The clicked view.
 */
private void startGame(View view) {
    TableRow row = (TableRow) view.getParent();
    TableLayout table = (TableLayout) row.getParent();
    ArrayList<Integer> orderedList = lg.getOrderedGameList();
    int index = indexes.get(table.indexOfChild(row) * menuColumns + row.indexOfChild(view));
    index = orderedList.indexOf(index);

    //avoid loading two games at once when pressing two buttons at once
    if (prefs.getSavedCurrentGame() != DEFAULT_CURRENT_GAME) {
        return;
    }

    prefs.saveCurrentGame(index);
    Intent intent = new Intent(getApplicationContext(), GameManager.class);
    intent.putExtra(GAME, index);
    startActivityForResult(intent, 0);
}
 
源代码2 项目: TelePlus-Android   文件: EmbedBottomSheet.java
public void updateTextureViewPosition() {
    View view = videoView.getAspectRatioView();
    view.getLocationInWindow(position);
    position[0] -= getLeftInset();

    if (!videoView.isInline() && !animationInProgress) {
        TextureView textureView = videoView.getTextureView();
        textureView.setTranslationX(position[0]);
        textureView.setTranslationY(position[1]);
        View textureImageView = videoView.getTextureImageView();
        if (textureImageView != null) {
            textureImageView.setTranslationX(position[0]);
            textureImageView.setTranslationY(position[1]);
        }
    }
    View controlsView = videoView.getControlsView();
    if (controlsView.getParent() == container) {
        controlsView.setTranslationY(position[1]);
    } else {
        controlsView.setTranslationY(0);
    }
}
 
源代码3 项目: VideoOS-Android-SDK   文件: VenvyUIUtil.java
public static boolean removeViewFromParent(View view) {

        if (null == view) {
            return false;
        }
        final ViewParent parent = view.getParent();
        if (parent == null) {
            return false;
        }
        if (parent instanceof ViewGroup) {
            ((ViewGroup) parent).removeView(view);
        } else {
            return false;
        }
        return true;
    }
 
/**
 * Sets the Empty View to be used by the Adapter View.
 * <p/>
 * We need it handle it ourselves so that we can Pull-to-Refresh when the
 * Empty View is shown.
 * <p/>
 * Please note, you do <strong>not</strong> usually need to call this method
 * yourself. Calling setEmptyView on the AdapterView will automatically call
 * this method and set everything up. This includes when the Android
 * Framework automatically sets the Empty View based on it's ID.
 * 
 * @param newEmptyView - Empty View to be used
 */
public final void setEmptyView(View newEmptyView) {
	FrameLayout refreshableViewWrapper = getRefreshableViewWrapper();

	if (null != newEmptyView) {
		// New view needs to be clickable so that Android recognizes it as a
		// target for Touch Events
		newEmptyView.setClickable(true);

		ViewParent newEmptyViewParent = newEmptyView.getParent();
		if (null != newEmptyViewParent && newEmptyViewParent instanceof ViewGroup) {
			((ViewGroup) newEmptyViewParent).removeView(newEmptyView);
		}

		// We need to convert any LayoutParams so that it works in our
		// FrameLayout
		FrameLayout.LayoutParams lp = convertEmptyViewLayoutParams(newEmptyView.getLayoutParams());
		if (null != lp) {
			refreshableViewWrapper.addView(newEmptyView, lp);
		} else {
			refreshableViewWrapper.addView(newEmptyView);
		}
	}

	if (mRefreshableView instanceof EmptyViewMethodAccessor) {
		((EmptyViewMethodAccessor) mRefreshableView).setEmptyViewInternal(newEmptyView);
	} else {
		mRefreshableView.setEmptyView(newEmptyView);
	}
	mEmptyView = newEmptyView;
}
 
源代码5 项目: android-animations   文件: Slide.java
public static AnimatorSet OutRight(View view){
    AnimatorSet animatorSet = new AnimatorSet();
    ViewGroup parent = (ViewGroup) view.getParent();
    int distance = parent.getWidth() - view.getLeft();

    ObjectAnimator object1 = ObjectAnimator.ofFloat(view,"alpha", 1, 0);
    ObjectAnimator object2 = ObjectAnimator.ofFloat(view,"translationX", 0, distance);

    animatorSet.playTogether(object1, object2);
    return animatorSet;
}
 
源代码6 项目: SlideAndDragListView   文件: DragManager.java
private void getOffset(View current, View decorView, int[] array) {
    if (current != decorView) {
        getOffset(current, array);
        if (current.getParent() != null) {
            View view = (View) current.getParent();
            getOffset(view, decorView, array);
        }
    }
}
 
/**
 * Return true if child is a descendant of parent, (or equal to the parent).
 */
private static boolean isViewDescendantOf(View child, View parent) {
    if (child == parent) {
        return true;
    }

    final ViewParent theParent = child.getParent();
    return (theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent);
}
 
源代码8 项目: Nimingban   文件: ViewDragHelper.java
/**
 * Capture a specific child view for dragging within the parent. The callback will be notified
 * but {@link Callback#tryCaptureView(android.view.View, int)} will not be asked permission to
 * capture this view.
 *
 * @param childView Child view to capture
 * @param activePointerId ID of the pointer that is dragging the captured child view
 */
public void captureChildView(View childView, int activePointerId) {
    if (childView.getParent() != mParentView) {
        throw new IllegalArgumentException("captureChildView: parameter must be a descendant " +
                "of the ViewDragHelper's tracked parent view (" + mParentView + ")");
    }

    mCapturedView = childView;
    mActivePointerId = activePointerId;
    mCallback.onViewCaptured(childView, activePointerId);
    setDragState(STATE_DRAGGING);
}
 
源代码9 项目: BoardView   文件: BoardView.java
private ViewGroup removeParent(View view){
    if(view == null){
        return null;
    }
    ViewGroup viewGroup = ((ViewGroup)view.getParent());
    if(viewGroup != null){
        viewGroup.removeView(view);
    }
    return viewGroup;
}
 
源代码10 项目: TabPager   文件: ViewUtils.java
/**
 * 从View的Parent中移除该View
 *
 * @param view 要移除的View对象
 */
public static void removeFromParent(View view) {
    if (null != view) {
        ViewParent parent = view.getParent();
        if (null != parent && parent instanceof ViewGroup) {
            ((ViewGroup) parent).removeView(view);
        }
    }
}
 
源代码11 项目: Mover   文件: ViewAnimationUtils.java
/**
 * Returns an Animator which can animate a clipping circle.
 * <p>
 * Any shadow cast by the View will respect the circular clip from this animator.
 * <p>
 * Only a single non-rectangular clip can be applied on a View at any time.
 * Views clipped by a circular reveal animation take priority over
 * {@link android.view.View#setClipToOutline(boolean) View Outline clipping}.
 * <p>
 * Note that the animation returned here is a one-shot animation. It cannot
 * be re-used, and once started it cannot be paused or resumed.
 *
 * @param view The View will be clipped to the animating circle.
 * @param centerX The x coordinate of the center of the animating circle.
 * @param centerY The y coordinate of the center of the animating circle.
 * @param startRadius The starting radius of the animating circle.
 * @param endRadius The ending radius of the animating circle.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static codetail.animation.Animator createCircularReveal(View view,
                                            int centerX,  int centerY,
                                            float startRadius, float endRadius) {

    if(codetail.animation.Animator.LOLLIPOP){
        return new codetail.animation.Animator(android.view.ViewAnimationUtils
                .createCircularReveal(view, centerX, centerY, startRadius, endRadius));
    }

    if(!(view.getParent() instanceof RevealAnimator)){
        throw new IllegalArgumentException("View must be inside dreamers.widget.RevealLayout.");
    }

    RevealAnimator revealLayout = (RevealAnimator) view.getParent();
    revealLayout.setTarget(view);
    revealLayout.setCenter(centerX, centerY);

    Rect bounds = new Rect();
    view.getHitRect(bounds);

    ObjectAnimator reveal = ObjectAnimator.ofFloat(revealLayout, "revealRadius", startRadius, endRadius);
    reveal.addListener(new RevealAnimator.RevealFinished(revealLayout, bounds));

    return new codetail.animation.Animator(reveal);
}
 
源代码12 项目: sealtalk-android   文件: MultiVideoCallActivity.java
@Override
public void onRemoteUserLeft(String userId, RongCallCommon.CallDisconnectedReason reason) {
    //incoming状态,localViewUserId为空
    if (localViewUserId == null)
        return;
    if (localViewUserId.equals(userId)) {
        localViewContainer.removeAllViews();
        String currentUserId = RongIMClient.getInstance().getCurrentUserId();
        FrameLayout remoteVideoView = (FrameLayout) remoteViewContainer.findViewWithTag(currentUserId);
        localView = (SurfaceView) remoteVideoView.getChildAt(0);
        remoteVideoView.removeAllViews();
        localViewContainer.addView(localView);
        TextView topUserNameView = (TextView) topContainer.findViewById(R.id.rc_voip_user_name);
        UserInfo userInfo = RongContext.getInstance().getUserInfoFromCache(currentUserId);
        if (userInfo != null) {
            topUserNameView.setText(userInfo.getName());
        } else {
            topUserNameView.setText(currentUserId);
        }
        localViewUserId = currentUserId;
    }

    View singleRemoteView = remoteViewContainer.findViewWithTag(userId + "view");

    if (singleRemoteView == null)
        return;

    LinearLayout container = (LinearLayout) singleRemoteView.getParent();
    container.removeView(singleRemoteView);
    if (container.equals(remoteViewContainer2)) {
        if (remoteViewContainer1.getChildCount() > 0) {
            View childView = remoteViewContainer1.getChildAt(0);
            remoteViewContainer1.removeView(childView);
            remoteViewContainer2.addView(childView);
        }
    }
}
 
源代码13 项目: litho   文件: TransitionManager.java
private void recursivelySetChildClippingForView(View view, boolean clipChildren) {
  if (view instanceof ComponentHost) {
    if (clipChildren) {
      ((ComponentHost) view).restoreChildClipping();
    } else {
      ((ComponentHost) view).temporaryDisableChildClipping();
    }
  }

  final ViewParent parent = view.getParent();
  if (parent instanceof ComponentHost) {
    recursivelySetChildClippingForView((View) parent, clipChildren);
  }
}
 
源代码14 项目: MaterialQQLite   文件: ViewDragHelper.java
/**
 * Capture a specific child view for dragging within the parent. The
 * callback will be notified but
 * {@link me.imid.swipebacklayout.lib.ViewDragHelper.Callback#tryCaptureView(android.view.View, int)}
 * will not be asked permission to capture this view.
 *
 * @param childView       Child view to capture
 * @param activePointerId ID of the pointer that is dragging the captured
 *                        child view
 */
public void captureChildView(View childView, int activePointerId) {
    if (childView.getParent() != mParentView) {
        throw new IllegalArgumentException("captureChildView: parameter must be a descendant "
                + "of the ViewDragHelper's tracked parent view (" + mParentView + ")");
    }

    mCapturedView = childView;
    mActivePointerId = activePointerId;
    mCallback.onViewCaptured(childView, activePointerId);
    setDragState(STATE_DRAGGING);
}
 
源代码15 项目: licodeAndroidClient   文件: VideoGridLayout.java
/**
 * signals that the given view was just tapped. This indicates the view
 * should switch from normal to enlarged display, or back to normal?
 * Implicitly calls requestLayout!
 * 
 * @param v
 *            The tapped view.
 * @return true if the element is now zoomed, false if it was returned to
 *         normal size
 */
public boolean onTapped(View v) {
	if (v == null || v.getParent() != this) {
		return false;
	}

	if (mZoomedChild != v) {
		setZoomedChild(v);
	} else {
		setZoomedChild(null);
	}
	requestLayout();
	return v == mZoomedChild;
}
 
源代码16 项目: UltimateRecyclerView   文件: SwipeLayout.java
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child == null) return;
    int gravity = Gravity.NO_GRAVITY;
    try {
        gravity = (Integer) params.getClass().getField("gravity").get(params);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (gravity > 0) {
        gravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));

        if ((gravity & Gravity.LEFT) == Gravity.LEFT) {
            mDragEdges.put(DragEdge.Left, child);
        }
        if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) {
            mDragEdges.put(DragEdge.Right, child);
        }
        if ((gravity & Gravity.TOP) == Gravity.TOP) {
            mDragEdges.put(DragEdge.Top, child);
        }
        if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
            mDragEdges.put(DragEdge.Bottom, child);
        }
    } else {
        for (Map.Entry<DragEdge, View> entry : mDragEdges.entrySet()) {
            if (entry.getValue() == null) {
                //means used the drag_edge attr, the no gravity child should be use set
                mDragEdges.put(entry.getKey(), child);
                break;
            }
        }
    }
    if (child.getParent() == this) {
        return;
    }
    super.addView(child, index, params);
}
 
源代码17 项目: BigApp_Discuz_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.FILL_PARENT, LayoutParams.FILL_PARENT));

			this.setVisibility(View.GONE);
			container.addView(this);
		} else {
			// 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();
		}
	}
 
源代码18 项目: V.FlyoutTest   文件: ViewCompat.java
@Override
public ViewParent getParentForAccessibility(View view) {
    return view.getParent();
}
 
源代码19 项目: Tweetin   文件: PhotoViewAttacher.java
@Override
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
            case ACTION_DOWN:
                // First, disable the Parent from intercepting the touch
                // event
                if (null != parent)
                    parent.requestDisallowInterceptTouchEvent(true);
                else
                    Log.i(LOG_TAG, "onTouch getParent() returned null");

                // If we're flinging, and the user presses down, cancel
                // fling
                cancelFling();
                break;

            case ACTION_CANCEL:
            case ACTION_UP:
                // If the user has zoomed less than min scale, zoom back
                // to min scale
                if (getScale() < mMinScale) {
                    RectF rect = getDisplayRect();
                    if (null != rect) {
                        v.post(new AnimatedZoomRunnable(getScale(), mMinScale,
                                rect.centerX(), rect.centerY()));
                        handled = true;
                    }
                }
                break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector
                && mScaleDragDetector.onTouchEvent(ev)) {
            handled = true;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }
    }

    return handled;
}
 
源代码20 项目: android_9.0.0_r45   文件: SimpleMonthView.java
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // We need to handle focus change within the SimpleMonthView because we are simulating
    // multiple Views. The arrow keys will move between days until there is no space (no
    // day to the left, top, right, or bottom). Focus forward and back jumps out of the
    // SimpleMonthView, skipping over other SimpleMonthViews in the parent ViewPager
    // to the next focusable View in the hierarchy.
    boolean focusChanged = false;
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (event.hasNoModifiers()) {
                focusChanged = moveOneDay(!isLayoutRtl());
            }
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay > 7) {
                    mHighlightedDay -= 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.hasNoModifiers()) {
                ensureFocusedDay();
                if (mHighlightedDay <= mDaysInMonth - 7) {
                    mHighlightedDay += 7;
                    focusChanged = true;
                }
            }
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (mHighlightedDay != -1) {
                onDayClicked(mHighlightedDay);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_TAB: {
            int focusChangeDirection = 0;
            if (event.hasNoModifiers()) {
                focusChangeDirection = View.FOCUS_FORWARD;
            } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                focusChangeDirection = View.FOCUS_BACKWARD;
            }
            if (focusChangeDirection != 0) {
                final ViewParent parent = getParent();
                // move out of the ViewPager next/previous
                View nextFocus = this;
                do {
                    nextFocus = nextFocus.focusSearch(focusChangeDirection);
                } while (nextFocus != null && nextFocus != this &&
                        nextFocus.getParent() == parent);
                if (nextFocus != null) {
                    nextFocus.requestFocus();
                    return true;
                }
            }
            break;
        }
    }
    if (focusChanged) {
        invalidate();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}
 
 方法所在类
 同类方法