当前位置: 首页>>代码示例>>Java>>正文


Java View.getHitRect方法代码示例

本文整理汇总了Java中android.view.View.getHitRect方法的典型用法代码示例。如果您正苦于以下问题:Java View.getHitRect方法的具体用法?Java View.getHitRect怎么用?Java View.getHitRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.View的用法示例。


在下文中一共展示了View.getHitRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findClickableViewInChild

import android.view.View; //导入方法依赖的package包/类
private boolean findClickableViewInChild(View view, int x, int y) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            final Rect rect = new Rect();
            child.getHitRect(rect);

            final boolean contains = rect.contains(x, y);
            if (contains) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != childView) {
        return (view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode()));
    }

    return view.isFocusableInTouchMode();
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:20,代码来源:MaterialRippleLayout.java

示例2: setPendIntent

import android.view.View; //导入方法依赖的package包/类
/***
 *
 * @param remoteViews
 *            当前
 * @param remoteview
 *            当前remoteviews的view
 * @param oldRemoteView
 *            旧的view
 */
public void setPendIntent(RemoteViews remoteViews, View remoteview, View oldRemoteView) {
	if (findPendIntents() > 0) {
		// view2+clickIntents=>区域和事件
		Iterator<Map.Entry<Integer, PendingIntent>> set = clickIntents.entrySet().iterator();
		List<RectInfo> list = new ArrayList<>();
		// 区域对应点击事件
		while (set.hasNext()) {
			Map.Entry<Integer, PendingIntent> e = set.next();
			View view = oldRemoteView.findViewById(e.getKey());
			if (view != null) {
				Rect rect = new Rect();
				view.getHitRect(rect);
				list.add(new RectInfo(rect, e.getValue()));
			}
		}
		// 根据区域查找id,设置点击事件
		if (remoteview instanceof ViewGroup) {
			setIntentByViewGroup(remoteViews, (ViewGroup) remoteview, list);
		}
	}
}
 
开发者ID:codehz,项目名称:container,代码行数:31,代码来源:PendIntentCompat.java

示例3: onTouch

import android.view.View; //导入方法依赖的package包/类
/**
 * Monitors the touch event.
 * If the action is ACTION_DOWN or ACTION_MOVE, the LinearLayout is traversed to get the hitRect of each child.
 * Each child hitRect is checked to see if it contains x,y touch co-ordinates.
 * If it does, selectChild(index) method is called.
 * @param view
 * @param motionEvent
 * @return
 */
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    switch (motionEvent.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
            int x = (int) motionEvent.getX();
            int y = (int) motionEvent.getY();
            Rect hitRect = new Rect();
            View v;

            for (int i = 0; i < getChildCount(); i++) {
                v = getChildAt(i);
                v.getHitRect(hitRect);
                if (hitRect.contains(x, y)) {
                    selectChild(i);
                    break;
                }
            }
            break;
        default:
            break;
    }

    return true;
}
 
开发者ID:GoodieBag,项目名称:HorizontalPicker,代码行数:35,代码来源:HorizontalPicker.java

示例4: findClickableViewInChild

import android.view.View; //导入方法依赖的package包/类
private boolean findClickableViewInChild(View view, int x, int y) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            Rect rect = new Rect();
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != this.childView) {
        return view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode());
    }
    return view.isFocusableInTouchMode();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:MaterialRippleLayout.java

示例5: isEventOverChild

import android.view.View; //导入方法依赖的package包/类
private boolean isEventOverChild(MotionEvent ev, List<View> children) {
    final int actionIndex = ev.getActionIndex();
    final float x = ev.getX(actionIndex) + getScrollX();
    final float y = ev.getY(actionIndex) + getScrollY();

    for (View child : children) {
        if (!canViewReceivePointerEvents(child)) {
            continue;
        }
        child.getHitRect(sHitFrame);

        // child can receive the motion event.
        if (sHitFrame.contains((int) x, (int) y)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:19,代码来源:NonLockingScrollView.java

示例6: isInIgnoredView

import android.view.View; //导入方法依赖的package包/类
private boolean isInIgnoredView(MotionEvent ev) {
	Rect rect = new Rect();
	for (View v : mIgnoredViews) {
		v.getHitRect(rect);
		if (rect.contains((int)ev.getX(), (int)ev.getY())) return true;
	}
	return false;
}
 
开发者ID:ChenTianSaber,项目名称:DailyZhiHu,代码行数:9,代码来源:CustomViewAbove.java

示例7: isPinnedViewTouched

import android.view.View; //导入方法依赖的package包/类
private boolean isPinnedViewTouched(View view, float x, float y) {
    view.getHitRect(mTouchRect);

    // by taping top or bottom padding, the list performs on click on a border item.
    // we don't add top padding here to keep behavior consistent.
    mTouchRect.top += mTranslateY;

    mTouchRect.bottom += mTranslateY + getPaddingTop();
    mTouchRect.left += getPaddingLeft();
    mTouchRect.right -= getPaddingRight();
    return mTouchRect.contains((int)x, (int)y);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:PinnedSectionListView.java

示例8: getChildAt

import android.view.View; //导入方法依赖的package包/类
/**
 * Draws the next child of the FlatViewGroup.  Each draw view calls FlatViewGroup.drawNextChild,
 * which keeps track of the current child index to draw.
 *
 * @param canvas The canvas to draw on.
 */
/* package */ void drawNextChild(Canvas canvas) {
  View child = getChildAt(mDrawChildIndex);
  if (child instanceof FlatViewGroup) {
    super.drawChild(canvas, child, getDrawingTime());
  } else {
    // Make sure non-React Views clip properly.
    canvas.save(Canvas.CLIP_SAVE_FLAG);
    child.getHitRect(VIEW_BOUNDS);
    canvas.clipRect(VIEW_BOUNDS);
    super.drawChild(canvas, child, getDrawingTime());
    canvas.restore();
  }

  ++mDrawChildIndex;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:22,代码来源:FlatViewGroup.java

示例9: drawShadow

import android.view.View; //导入方法依赖的package包/类
private void drawShadow(Canvas canvas, View child) {
    final Rect childRect = mTmpRect;
    child.getHitRect(childRect);

    if ((mEdgeFlag & EDGE_LEFT) != 0) {
        mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top,
                childRect.left, childRect.bottom);
        mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowLeft.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_RIGHT) != 0) {
        mShadowRight.setBounds(childRect.right, childRect.top,
                childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom);
        mShadowRight.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowRight.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_BOTTOM) != 0) {
        mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right,
                childRect.bottom + mShadowBottom.getIntrinsicHeight());
        mShadowBottom.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowBottom.draw(canvas);
    }
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:26,代码来源:SwipeBackLayout.java

示例10: drawShadow

import android.view.View; //导入方法依赖的package包/类
private void drawShadow(Canvas canvas, View child) {
    final Rect childRect = mTmpRect;
    child.getHitRect(childRect);

    mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top,
            childRect.left, childRect.bottom);
    mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
    mShadowLeft.draw(canvas);
}
 
开发者ID:wheat7,项目名称:Cashew,代码行数:10,代码来源:SwipeBackLayout.java

示例11: findChildByPoint

import android.view.View; //导入方法依赖的package包/类
private View findChildByPoint(int x, int y) {
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        Rect rect = new Rect();
        child.getHitRect(rect);
        if (rect.contains(x, y)) {
            return child;
        }
    }
    return null;
}
 
开发者ID:mmjang,项目名称:ankihelper,代码行数:13,代码来源:BigBangLayout.java

示例12: drawShadow

import android.view.View; //导入方法依赖的package包/类
private void drawShadow(Canvas canvas, View child) {
    final Rect childRect = mTmpRect;
    child.getHitRect(childRect);

    if ((mEdgeFlag & EDGE_LEFT) != 0) {
        mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top,
                childRect.left, childRect.bottom);
        mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowLeft.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_RIGHT) != 0) {
        mShadowRight.setBounds(childRect.right, childRect.top,
                childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom);
        mShadowRight.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowRight.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_BOTTOM) != 0) {
        mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right,
                childRect.bottom + mShadowBottom.getIntrinsicHeight());
        mShadowBottom.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowBottom.draw(canvas);
    }

    if ((mEdgeFlag & EDGE_TOP) != 0) {
        mShadowTop.setBounds(childRect.left, childRect.top - mShadowTop.getIntrinsicHeight(),
                childRect.right, childRect.top + getStatusBarHeight());
        mShadowTop.setAlpha((int) (mScrimOpacity * FULL_ALPHA));
        mShadowTop.draw(canvas);
    }
}
 
开发者ID:ccrama,项目名称:Slide-RSS,代码行数:33,代码来源:SwipeBackLayout.java

示例13: isDrawerVisible

import android.view.View; //导入方法依赖的package包/类
private boolean isDrawerVisible(View view) {

        Rect scrollBounds = new Rect();
        view.getHitRect(scrollBounds);
        if (view.findViewById(R.id.drawer_layout).findViewById(R.id.left_drawer).getLocalVisibleRect(scrollBounds)) {
            return true;
        } else {
            return false;
        }
    }
 
开发者ID:R-a-dio,项目名称:R-a-dio-Amazing-Android-App,代码行数:11,代码来源:ActivityMain.java

示例14: onInterceptTouchEvent

import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
	if (mLocked) {
		return false;
	}

	final int action = event.getAction();

	float x = event.getX();
	float y = event.getY();

	final Rect frame = mFrame;
	final View handle = mHandle;

	handle.getHitRect(frame);
	if (!mTracking && !frame.contains((int) x, (int) y)) {
		return false;
	}

	if (action == MotionEvent.ACTION_DOWN) {
		mTracking = true;

		handle.setPressed(true);
		// Must be called before prepareTracking()
		prepareContent();

		// Must be called after prepareContent()
		if (mOnDrawerScrollListener != null) {
			mOnDrawerScrollListener.onScrollStarted();
		}

		if (mVertical) {
			final int top = mHandle.getTop();
			mTouchDelta = (int) y - top;
			prepareTracking(top);
		} else {
			final int left = mHandle.getLeft();
			mTouchDelta = (int) x - left;
			prepareTracking(left);
		}
		mVelocityTracker.addMovement(event);
	}

	return onTouchEvent(event);
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:46,代码来源:SlidingDrawer.java

示例15: onTouchEvent

import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
        if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) {
            showMenuRunnable = new Runnable() {
                @Override
                public void run() {
                    if (getParent() != null) {
                        getParent().requestDisallowInterceptTouchEvent(true);
                    }
                    toggleSubMenu();
                }
            };
            AndroidUtilities.runOnUIThread(showMenuRunnable, 200);
        }
    } else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
        if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) {
            if (event.getY() > getHeight()) {
                if (getParent() != null) {
                    getParent().requestDisallowInterceptTouchEvent(true);
                }
                toggleSubMenu();
                return true;
            }
        } else if (popupWindow != null && popupWindow.isShowing()) {
            getLocationOnScreen(location);
            float x = event.getX() + location[0];
            float y = event.getY() + location[1];
            popupLayout.getLocationOnScreen(location);
            x -= location[0];
            y -= location[1];
            selectedMenuView = null;
            for (int a = 0; a < popupLayout.getItemsCount(); a++) {
                View child = popupLayout.getItemAt(a);
                child.getHitRect(rect);
                if ((Integer) child.getTag() < 100) {
                    if (!rect.contains((int) x, (int) y)) {
                        child.setPressed(false);
                        child.setSelected(false);
                        if (Build.VERSION.SDK_INT == 21) {
                            child.getBackground().setVisible(false, false);
                        }
                    } else {
                        child.setPressed(true);
                        child.setSelected(true);
                        if (Build.VERSION.SDK_INT >= 21) {
                            if (Build.VERSION.SDK_INT == 21) {
                                child.getBackground().setVisible(true, false);
                            }
                            child.drawableHotspotChanged(x, y - child.getTop());
                        }
                        selectedMenuView = child;
                    }
                }
            }
        }
    } else if (popupWindow != null && popupWindow.isShowing() && event.getActionMasked() == MotionEvent.ACTION_UP) {
        if (selectedMenuView != null) {
            selectedMenuView.setSelected(false);
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) selectedMenuView.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) selectedMenuView.getTag());
            }
            popupWindow.dismiss(allowCloseAnimation);
        } else {
            popupWindow.dismiss();
        }
    } else {
        if (selectedMenuView != null) {
            selectedMenuView.setSelected(false);
            selectedMenuView = null;
        }
    }
    return super.onTouchEvent(event);
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:77,代码来源:ActionBarMenuItem.java


注:本文中的android.view.View.getHitRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。