Java Code Examples for android.view.View#getLocationOnScreen()
The following examples show how to use
android.view.View#getLocationOnScreen() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HomeMenuWindow.java From Tok-Android with GNU General Public License v3.0 | 6 votes |
public static int[] calculatePopWindowPos(final View anchorView, final View contentView) { final int windowPos[] = new int[2]; final int anchorLoc[] = new int[2]; anchorView.getLocationOnScreen(anchorLoc); final int anchorHeight = anchorView.getHeight(); final int screenHeight = ScreenUtils.getScreenHeight(anchorView.getContext()); final int screenWidth = ScreenUtils.getScreenWidth(anchorView.getContext()); contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); final int windowHeight = contentView.getMeasuredHeight(); final int windowWidth = contentView.getMeasuredWidth(); final boolean isNeedShowUp = (screenHeight - anchorLoc[1] - anchorHeight < windowHeight); if (isNeedShowUp) { windowPos[0] = screenWidth - windowWidth; windowPos[1] = anchorLoc[1] - windowHeight; } else { windowPos[0] = screenWidth - windowWidth; windowPos[1] = anchorLoc[1] + anchorHeight; } return windowPos; }
Example 2
Source File: Utility.java From iBeebo with GNU General Public License v3.0 | 6 votes |
public static Rect locateView(View v) { int[] location = new int[2]; if (v == null) { return null; } try { v.getLocationOnScreen(location); } catch (NullPointerException npe) { // Happens when the view doesn't exist on screen anymore. return null; } Rect locationRect = new Rect(); locationRect.left = location[0]; locationRect.top = location[1]; locationRect.right = locationRect.left + v.getWidth(); locationRect.bottom = locationRect.top + v.getHeight(); return locationRect; }
Example 3
Source File: Utility.java From iBeebo with GNU General Public License v3.0 | 6 votes |
public static Rect locateView(View v) { int[] location = new int[2]; if (v == null) { return null; } try { v.getLocationOnScreen(location); } catch (NullPointerException npe) { // Happens when the view doesn't exist on screen anymore. return null; } Rect locationRect = new Rect(); locationRect.left = location[0]; locationRect.top = location[1]; locationRect.right = locationRect.left + v.getWidth(); locationRect.bottom = locationRect.top + v.getHeight(); return locationRect; }
Example 4
Source File: TouchRecyclerView.java From YImagePicker with Apache License 2.0 | 6 votes |
private boolean isTouchPointInView(View view, float x, float y) { if (view == null) { return false; } int[] location = new int[2]; view.getLocationOnScreen(location); int left = location[0]; int top = location[1]; int right = left + view.getMeasuredWidth(); int bottom = top + view.getMeasuredHeight(); //view.isClickable() && if (y >= top && y <= bottom && x >= left && x <= right) { return true; } return false; }
Example 5
Source File: AppBarWithToolbarTest.java From material-components-android with Apache License 2.0 | 6 votes |
/** * Tests a AppBarLayout + scrolling content with fitSystemWindows = undefined, with a * fitSystemWindows = true parent */ @Test public void testScrollingContentPositionWithFitSystemWindowsParent() throws Throwable { configureContent( R.layout.design_appbar_toolbar_scroll_fitsystemwindows_parent, R.string.design_appbar_toolbar_scroll_tabs_pin); final int[] appbarOnScreenXY = new int[2]; mAppBar.getLocationOnScreen(appbarOnScreenXY); final View scrollingContent = mCoordinatorLayout.findViewById(R.id.scrolling_content); final int[] scrollingContentOnScreenXY = new int[2]; scrollingContent.getLocationOnScreen(scrollingContentOnScreenXY); // Assert that they have the same left assertEquals(appbarOnScreenXY[0], scrollingContentOnScreenXY[0]); // ...and the same width assertEquals(mAppBar.getWidth(), scrollingContent.getWidth()); // ...and are vertically stacked assertEquals(mAppBar.getBottom(), scrollingContent.getTop()); }
Example 6
Source File: NewsChannelAdapter.java From Toutiao with Apache License 2.0 | 6 votes |
/** * 添加需要移动的 镜像View */ private ImageView addMirrorView(ViewGroup parent, RecyclerView recyclerView, View view) { /** * 我们要获取cache首先要通过setDrawingCacheEnable方法开启cache,然后再调用getDrawingCache方法就可以获得view的cache图片了。 buildDrawingCache方法可以不用调用,因为调用getDrawingCache方法时,若果cache没有建立,系统会自动调用buildDrawingCache方法生成cache。 若想更新cache, 必须要调用destoryDrawingCache方法把旧的cache销毁,才能建立新的。 当调用setDrawingCacheEnabled方法设置为false, 系统也会自动把原来的cache销毁。 */ view.destroyDrawingCache(); view.setDrawingCacheEnabled(true); final ImageView mirrorView = new ImageView(recyclerView.getContext()); Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); mirrorView.setImageBitmap(bitmap); view.setDrawingCacheEnabled(false); int[] locations = new int[2]; view.getLocationOnScreen(locations); int[] parenLocations = new int[2]; recyclerView.getLocationOnScreen(parenLocations); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(bitmap.getWidth(), bitmap.getHeight()); params.setMargins(locations[0], locations[1] - parenLocations[1], 0, 0); parent.addView(mirrorView, params); return mirrorView; }
Example 7
Source File: ELinkageScrollLayout.java From ELinkageScroll with Apache License 2.0 | 6 votes |
/** * 获取手指触摸的target * * @param rawX * @param rawY * @return */ private View getTouchTarget(float rawX, float rawY) { int count = getChildCount(); for (int i = 0; i < count; i++) { View target = getChildAt(i); int[] location = new int[2]; target.getLocationOnScreen(location); int left = location[0]; int top = location[1]; int right = left + target.getWidth(); int bottom = top + target.getHeight(); RectF rect = new RectF(left, top, right, bottom); if (rect.contains(rawX, rawY)) { return target; } } return null; }
Example 8
Source File: WXViewUtils.java From ucar-weex-core with Apache License 2.0 | 6 votes |
public static boolean onScreenArea(View view) { if (view == null || view.getVisibility() != View.VISIBLE) { return false; } int[] p = new int[2]; view.getLocationOnScreen(p); LayoutParams lp = view.getLayoutParams(); int viewH = 0; if (lp != null) { viewH = lp.height; } else { viewH = view.getHeight(); } return (p[1] > 0 && (p[1] - WXViewUtils.getScreenHeight(WXEnvironment.sApplication) < 0)) || (viewH + p[1] > 0 && p[1] <= 0); }
Example 9
Source File: DidiLayout.java From DidiLayout with Apache License 2.0 | 5 votes |
private boolean isViewUnder(View view, int x, int y) { if (view == null) return false; int[] viewLocation = new int[2]; view.getLocationOnScreen(viewLocation); int[] parentLocation = new int[2]; this.getLocationOnScreen(parentLocation); int screenX = parentLocation[0] + x; int screenY = parentLocation[1] + y; return screenX >= viewLocation[0] && screenX < viewLocation[0] + view.getWidth() && screenY >= viewLocation[1] && screenY < viewLocation[1] + view.getHeight(); }
Example 10
Source File: ItemOptionView.java From openlauncher with Apache License 2.0 | 5 votes |
private boolean isViewContains(View view, int rx, int ry) { view.getLocationOnScreen(_tempArrayOfInt2); int x = _tempArrayOfInt2[0]; int y = _tempArrayOfInt2[1]; int w = view.getWidth(); int h = view.getHeight(); if (rx < x || rx > x + w || ry < y || ry > y + h) { return false; } return true; }
Example 11
Source File: VideoListFragment.java From VideoDemoJava with MIT License | 5 votes |
public void removeVideoList() { int size = mList.size() - 1; for (int i = size; i > 0; i--) { mList.remove(i); } mAdapter.notifyItemRangeRemoved(1, size); final View view = mRecycler.getChildAt(0); final int[] location = new int[2]; view.getLocationOnScreen(location); final ImageView image = view.findViewById(R.id.adapter_video_list_image); final FrameLayout container = view.findViewById(R.id.adapter_video_list_container); final TextView title = view.findViewById(R.id.adapter_video_list_title); final LinearLayout bottom = view.findViewById(R.id.bottom_layout); title.postDelayed(new Runnable() { @Override public void run() { title.setVisibility(View.GONE); bottom.setVisibility(View.GONE); image.setVisibility(View.GONE); container.animate().scaleX((float) mAttr.getWidth() / container.getMeasuredWidth()) .scaleY((float) mAttr.getHeight() / container.getMeasuredHeight()) .setDuration(DURATION); view.animate().translationY(mAttr.getY() - location[1]).setDuration(DURATION); ObjectAnimator animator = ObjectAnimator.ofInt(mRoot, "backgroundColor", 0xff000000, 0x00000000); animator.setEvaluator(new ArgbEvaluator()); animator.setDuration(DURATION); animator.start(); } }, 250); }
Example 12
Source File: UiTestUtils.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
public static void swipeHorizontally(InstrumentationTestCase test, View v, Direction direction) { int[] xy = new int[2]; v.getLocationOnScreen(xy); final int viewWidth = v.getWidth(); final int viewHeight = v.getHeight(); float distanceFromEdge = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, v.getResources().getDisplayMetrics()); float xStart = xy[0] + ((direction == Direction.LEFT) ? (viewWidth - distanceFromEdge) : distanceFromEdge); float xEnd = xy[0] + ((direction == Direction.LEFT) ? distanceFromEdge : (viewWidth - distanceFromEdge)); float y = xy[1] + (viewHeight / 2.0f); TouchUtils.drag(test, xStart, xEnd, y, y, DRAG_STEP_COUNT); }
Example 13
Source File: RevealLayout.java From android-art-res with Apache License 2.0 | 5 votes |
private boolean isTouchPointInView(View view, int x, int y) { int[] location = new int[2]; view.getLocationOnScreen(location); int left = location[0]; int top = location[1]; int right = left + view.getMeasuredWidth(); int bottom = top + view.getMeasuredHeight(); if (view.isClickable() && y >= top && y <= bottom && x >= left && x <= right) { return true; } return false; }
Example 14
Source File: NowPlayingView.java From odyssey with GNU General Public License v3.0 | 5 votes |
/** * Checks if an input to coordinates lay within a View * * @param view View to check with * @param x x value of the input * @param y y value of the input * @return True if input coordinates lay within the given view */ private boolean isViewHit(View view, int x, int y) { int[] viewLocation = new int[2]; view.getLocationOnScreen(viewLocation); int[] parentLocation = new int[2]; this.getLocationOnScreen(parentLocation); int screenX = parentLocation[0] + x; int screenY = parentLocation[1] + y; return screenX >= viewLocation[0] && screenX < viewLocation[0] + view.getWidth() && screenY >= viewLocation[1] && screenY < viewLocation[1] + view.getHeight(); }
Example 15
Source File: TuSdkMovieScrollContent.java From PLDroidShortVideo with Apache License 2.0 | 5 votes |
private boolean isTouchPointInView(View view, float x) { int diff = 40; if (view == null) { return false; } int[] location = new int[2]; view.getLocationOnScreen(location); int left = location[0]; int right = left + view.getMeasuredWidth(); if ((x >= left && x <= right) ||(x >= left - diff && x <= right+diff)) { return true; } return false; }
Example 16
Source File: HorizontalListView.java From android-project-wo2b with Apache License 2.0 | 5 votes |
private boolean isEventWithinView(MotionEvent e, View child) { Rect viewRect = new Rect(); int[] childPosition = new int[2]; child.getLocationOnScreen(childPosition); int left = childPosition[0]; int right = left + child.getWidth(); int top = childPosition[1]; int bottom = top + child.getHeight(); viewRect.set(left, top, right, bottom); return viewRect.contains((int) e.getRawX(), (int) e.getRawY()); }
Example 17
Source File: HorizontalListView.java From AndroidPicker with MIT License | 5 votes |
private boolean isEventWithinView(MotionEvent e, View child) { Rect viewRect = new Rect(); int[] childPosition = new int[2]; child.getLocationOnScreen(childPosition); int left = childPosition[0]; int right = left + child.getWidth(); int top = childPosition[1]; int bottom = top + child.getHeight(); viewRect.set(left, top, right, bottom); return viewRect.contains((int) e.getRawX(), (int) e.getRawY()); }
Example 18
Source File: ViewInfo.java From ifican with Apache License 2.0 | 5 votes |
public ViewInfo(View v, int position) { int[] screenLocation = new int[2]; v.getLocationOnScreen(screenLocation); left = screenLocation[0]; top = screenLocation[1]; width = v.getWidth(); height = v.getHeight(); orientation = v.getResources().getConfiguration().orientation; this.position = position; }
Example 19
Source File: Utils.java From Emoji with Apache License 2.0 | 4 votes |
@NonNull static Point locationOnScreen(@NonNull final View view) { final int[] location = new int[2]; view.getLocationOnScreen(location); return new Point(location[0], location[1]); }
Example 20
Source File: SystemUtil.java From Android with MIT License | 4 votes |
/** * view Location in the screen * @param view * @return */ public static int[] locationOnScreen(View view) { int[] location = new int[2]; view.getLocationOnScreen(location); return location; }