本文整理汇总了Java中android.view.ViewParent类的典型用法代码示例。如果您正苦于以下问题:Java ViewParent类的具体用法?Java ViewParent怎么用?Java ViewParent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ViewParent类属于android.view包,在下文中一共展示了ViewParent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformMotionEventToLocal
import android.view.ViewParent; //导入依赖的package包/类
/**
* Recursive helper method that applies transformations in post-order.
*
* @param ev the on-screen motion event
*/
private static void transformMotionEventToLocal(@NonNull View view, @NonNull MotionEvent ev) {
final ViewParent parent = view.getParent();
if (parent instanceof View) {
final View vp = (View) parent;
transformMotionEventToLocal(vp, ev);
ev.offsetLocation(vp.getScrollX(), vp.getScrollY());
} // TODO: Use reflections to access ViewRootImpl
// else if (parent instanceof ViewRootImpl) {
// final ViewRootImpl vr = (ViewRootImpl) parent;
// ev.offsetLocation(0, vr.mCurScrollY);
// }
ev.offsetLocation(-view.getLeft(), -view.getTop());
Matrix matrix = view.getMatrix();
if (matrix != null) {
ev.transform(matrix);
}
}
示例2: requestDisallowInterceptTouchEvent
import android.view.ViewParent; //导入依赖的package包/类
/**
* 是否请求当前view的父view不要拦截事件
*
* @param view
* @param disallowIntercept true-请求父view不要拦截,false-父view可以拦截
*/
public static void requestDisallowInterceptTouchEvent(View view, boolean disallowIntercept)
{
ViewParent parent = view.getParent();
if (parent == null)
{
return;
}
parent.requestDisallowInterceptTouchEvent(disallowIntercept);
}
示例3: instantiateItem
import android.view.ViewParent; //导入依赖的package包/类
@Override
public Object instantiateItem(ViewGroup container, int position)
{
//对ViewPager页号求模取出View列表中要显示的项
position %= mList.size();
if (position < 0)
{
position = mList.size() + position;
}
ImageView v = mList.get(position);
pos = position;
v.setScaleType(ImageView.ScaleType.CENTER);
//如果View已经在之前添加到了一个父组件,则必须先remove,否则会抛出IllegalStateException。
ViewParent vp = v.getParent();
if (vp != null)
{
ViewGroup parent = (ViewGroup) vp;
parent.removeView(v);
}
v.setOnClickListener(v1 -> {
if (mViewPagerOnItemClickListener != null)
{
mViewPagerOnItemClickListener.onItemClick();
}
});
container.addView(v);
return v;
}
示例4: onDrag
import android.view.ViewParent; //导入依赖的package包/类
@Override
public void onDrag(float dx, float dy) {
if (mScaleDragDetector.isScaling()) {
return; // Do not drag if we are already scaling
}
if (DEBUG) {
LogManager.getLogger().d(LOG_TAG,
String.format("onDrag: dx: %.2f. dy: %.2f", dx, dy));
}
ImageView imageView = getImageView();
mSuppMatrix.postTranslate(dx, dy);
checkAndDisplayMatrix();
/**
* Here we decide whether to let the ImageView's parent to start taking
* over the touch event.
*
* First we check whether this function is enabled. We never want the
* parent to take over if we're scaling. We then check the edge we're
* on, and the direction of the scroll (i.e. if we're pulling against
* the edge, aka 'overscrolling', let the parent take over).
*/
ViewParent parent = imageView.getParent();
if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) {
if (mScrollEdge == EDGE_BOTH
|| (mScrollEdge == EDGE_LEFT && dx >= 1f)
|| (mScrollEdge == EDGE_RIGHT && dx <= -1f)) {
if (null != parent) {
parent.requestDisallowInterceptTouchEvent(false);
}
}
} else {
if (null != parent) {
parent.requestDisallowInterceptTouchEvent(true);
}
}
}
示例5: intersectVisibleToUser
import android.view.ViewParent; //导入依赖的package包/类
private boolean intersectVisibleToUser(Rect localRect) {
if (localRect == null || localRect.isEmpty() || this.mView.getWindowVisibility() != 0) {
return false;
}
ViewParent viewParent = this.mView.getParent();
while (viewParent instanceof View) {
View view = (View) viewParent;
if (ViewCompat.getAlpha(view) <= 0.0f || view.getVisibility() != 0) {
return false;
}
viewParent = view.getParent();
}
if (viewParent == null || !this.mView.getLocalVisibleRect(this.mTempVisibleRect)) {
return false;
}
return localRect.intersect(this.mTempVisibleRect);
}
示例6: requestChildFocus
import android.view.ViewParent; //导入依赖的package包/类
@Override
public void requestChildFocus(View child, View focused) {
/*
* Normally a ScrollView will scroll the child into view.
* Prevent this when a MessageWebView is first touched,
* assuming it already is at least partially in view.
*
*/
if (mSkipWebViewScroll &&
focused instanceof MessageWebView &&
focused.getGlobalVisibleRect(new Rect())) {
mSkipWebViewScroll = false;
super.requestChildFocus(child, child);
ViewParent parent = getParent();
if (parent != null) {
parent.requestChildFocus(this, focused);
}
} else {
super.requestChildFocus(child, focused);
}
}
示例7: setJSResponder
import android.view.ViewParent; //导入依赖的package包/类
public void setJSResponder(int reactTag, int initialReactTag, boolean blockNativeResponder) {
if (!blockNativeResponder) {
mJSResponderHandler.setJSResponder(initialReactTag, null);
return;
}
View view = mTagsToViews.get(reactTag);
if (initialReactTag != reactTag && view instanceof ViewParent) {
// In this case, initialReactTag corresponds to a virtual/layout-only View, and we already
// have a parent of that View in reactTag, so we can use it.
mJSResponderHandler.setJSResponder(initialReactTag, (ViewParent) view);
return;
}
if (mRootTags.get(reactTag)) {
SoftAssertions.assertUnreachable(
"Cannot block native responder on " + reactTag + " that is a root view");
}
mJSResponderHandler
.setJSResponder(initialReactTag, view.getParent());
}
示例8: getVirtualViewCoordinates
import android.view.ViewParent; //导入依赖的package包/类
/**
* Get virtual view coordinates of a given {@link View}.
* <p/>
* This function always returns the coordinate of the top-left corner of the given view,
* regardless of left-to-right (LTR) vs. right-to-left (RTL) mode. Note that in RTL mode, this
* is not the corner that corresponds to the block's workspace coordinates. Use
* {@link #getWorkspaceCoordinates(View, WorkspacePoint)} to obtain the workspace coordinates
* of a block from its view, adjusted for RTL mode if necessary.
*
* @param view The view to find the position of.
* @param viewPosition The Point to store the results in.
*/
public void getVirtualViewCoordinates(View view, ViewPoint viewPosition) {
int leftRelativeToWorkspace = view.getLeft();
int topRelativeToWorkspace = view.getTop();
// Move up the parent hierarchy and add parent-relative view coordinates.
ViewParent viewParent = view.getParent();
while (viewParent != null) {
if (viewParent instanceof WorkspaceView || viewParent instanceof RecyclerView) {
break;
}
leftRelativeToWorkspace += ((View) viewParent).getLeft();
topRelativeToWorkspace += ((View) viewParent).getTop();
viewParent = viewParent.getParent();
}
if (viewParent == null) {
throw new IllegalStateException(
"No WorkspaceView or RecyclerView found among view's parents.");
}
viewPosition.x = leftRelativeToWorkspace;
viewPosition.y = topRelativeToWorkspace;
}
示例9: onInitializeAccessibilityNodeInfo
import android.view.ViewParent; //导入依赖的package包/类
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
super.onInitializeAccessibilityNodeInfo(host, superNode);
copyNodeInfoNoChildren(info, superNode);
superNode.recycle();
info.setClassName(SlidingPaneLayout.class.getName());
info.setSource(host);
ViewParent parent = ViewCompat.getParentForAccessibility(host);
if (parent instanceof View) {
info.setParent((View) parent);
}
int childCount = SlidingPaneLayout.this.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = SlidingPaneLayout.this.getChildAt(i);
if (!filter(child) && child.getVisibility() == 0) {
ViewCompat.setImportantForAccessibility(child, 1);
info.addChild(child);
}
}
}
示例10: setEmptyView
import android.view.ViewParent; //导入依赖的package包/类
public final void setEmptyView(View newEmptyView) {
FrameLayout refreshableViewWrapper = getRefreshableViewWrapper();
if (newEmptyView != null) {
newEmptyView.setClickable(true);
ViewParent newEmptyViewParent = newEmptyView.getParent();
if (newEmptyViewParent != null && (newEmptyViewParent instanceof ViewGroup)) {
((ViewGroup) newEmptyViewParent).removeView(newEmptyView);
}
LayoutParams lp = convertEmptyViewLayoutParams(newEmptyView.getLayoutParams());
if (lp != null) {
refreshableViewWrapper.addView(newEmptyView, lp);
} else {
refreshableViewWrapper.addView(newEmptyView);
}
}
if (this.mRefreshableView instanceof EmptyViewMethodAccessor) {
((EmptyViewMethodAccessor) this.mRefreshableView).setEmptyViewInternal(newEmptyView);
} else {
((AbsListView) this.mRefreshableView).setEmptyView(newEmptyView);
}
this.mEmptyView = newEmptyView;
}
示例11: scrollToBar
import android.view.ViewParent; //导入依赖的package包/类
private void scrollToBar(int barIndex, int autoScrollAnimationTime) {
ViewParent parentView = getParent();
if (parentView instanceof ScrollView) {
final ScrollView parentScrollView = (ScrollView) parentView;
for (View view : views) {
if (view instanceof SystemView
&& view.isShown()) {
SystemView systemView = (SystemView) view;
if (systemView.containsBar(barIndex)) {
int scroll_max = getBottom() - parentScrollView.getHeight();
int scroll_min = 0;
float windowHeight = parentScrollView.getHeight();
float windowPlayingCentre = kWindowPlayingCentreFractionFromTop * windowHeight;
float sysFrac = systemView.fractionalScroll(barIndex);
float playingCentre = view.getTop() + view.getHeight() * sysFrac;
float scroll_y = playingCentre - windowPlayingCentre;
if (scroll_y < scroll_min)
scroll_y = scroll_min;
else if (scroll_y > scroll_max)
scroll_y = scroll_max;
slowSmoothScrollTo(parentScrollView, (int) scroll_y, autoScrollAnimationTime);
}
}
}
}
}
示例12: childAtPosition
import android.view.ViewParent; //导入依赖的package包/类
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
示例13: onTouchEvent
import android.view.ViewParent; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = super.onTouchEvent(event);
if (wxGesture != null) {
result |= wxGesture.onTouch(this, event);
}
ViewParent parent = getParent();
if(parent != null){
switch (event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN:
if(mLines < getLineCount()) {
//scrollable
parent.requestDisallowInterceptTouchEvent(true);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
parent.requestDisallowInterceptTouchEvent(false);
break;
}
}
return result;
}
示例14: childAtPosition
import android.view.ViewParent; //导入依赖的package包/类
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position
) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
示例15: onInitializeAccessibilityNodeInfo
import android.view.ViewParent; //导入依赖的package包/类
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
if (DrawerLayout.CAN_HIDE_DESCENDANTS) {
super.onInitializeAccessibilityNodeInfo(host, info);
} else {
AccessibilityNodeInfoCompat superNode = AccessibilityNodeInfoCompat.obtain(info);
super.onInitializeAccessibilityNodeInfo(host, superNode);
info.setSource(host);
ViewParent parent = ViewCompat.getParentForAccessibility(host);
if (parent instanceof View) {
info.setParent((View) parent);
}
copyNodeInfoNoChildren(info, superNode);
superNode.recycle();
addChildrenForAccessibility(info, (ViewGroup) host);
}
info.setClassName(DrawerLayout.class.getName());
info.setFocusable(false);
info.setFocused(false);
info.removeAction(AccessibilityActionCompat.ACTION_FOCUS);
info.removeAction(AccessibilityActionCompat.ACTION_CLEAR_FOCUS);
}