Created
July 31, 2015 09:39
-
-
Save whinc/db5f2fc649ffde51b161 to your computer and use it in GitHub Desktop.
工具方法,扩展Android中View的可触摸区域
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 扩展View的触摸区域 | |
| * @param view 需要扩展触摸区域的View | |
| * @param left 左边扩展范围(单位px,下同) | |
| * @param top 上边扩展范围 | |
| * @param right 右边扩展范围 | |
| * @param bottom 下边扩展范围 | |
| */ | |
| public static void extendTouchArea(final View view, final int left, final int top, final int right, final int bottom) { | |
| if (view == null || view.getParent() == null) { | |
| return; | |
| } | |
| final View parent = (View) view.getParent(); | |
| parent.post(new Runnable() { | |
| @Override | |
| public void run() { | |
| Rect touchArea = new Rect(); | |
| view.getHitRect(touchArea); | |
| touchArea.left += left; | |
| touchArea.top += top; | |
| touchArea.right += right; | |
| touchArea.bottom += bottom; | |
| parent.setTouchDelegate(new TouchDelegate(touchArea, view)); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment