我的Android进阶之旅------>android中getLocationInWindow 和 getLocationOnScreen的区别
2023-09-27 14:29:23 时间
View.getLocationInWindow(int[] location)
================================================================================================== 附上源代码 ================================================================================================== View.getLocationInWindow(int[] location)
Android | 音视频方向进阶路线及资源合集 但是系统相机和系统控件VideoView的局限性都是可定制型太差,系统相机的图像分辨率,视频码率以及VideoView的进度条等.
字节卷动 You will never know how excellent you are unless you impel yourself once.
一个控件在其父窗口中的坐标位置
View.getLocationOnScreen(int[] location)
一个控件在其整个屏幕上的坐标位置
getLocationInWindow是以B为原点的C的坐标
getLocationOnScreen以A为原点。
下面是getLocationOnScreen示例
start = (Button) findViewById(R.id.start); int []location=new int[2]; start.getLocationOnScreen(location); int x=location[0];//获取当前位置的横坐标 int y=location[1];//获取当前位置的纵坐标
下面是getLocationInWindow示例
start = (Button) findViewById(R.id.start); int []location=new int[2]; start.getLocationInWindow(location); int x=location[0];//获取当前位置的横坐标 int y=location[1];//获取当前位置的纵坐标
================================================================================================== 附上源代码 ================================================================================================== View.getLocationInWindow(int[] location)
/** * p Computes the coordinates of this view in its window. The argument * must be an array of two integers. After the method returns, the array * contains the x and y location in that order. /p * @param location an array of two integers in which to hold the coordinates public void getLocationInWindow(int[] location) { if (location == null || location.length 2) { throw new IllegalArgumentException("location must be an array of two integers"); if (mAttachInfo == null) { // When the view is not attached to a window, this method does not make sense location[0] = location[1] = 0; return; float[] position = mAttachInfo.mTmpTransformLocation; position[0] = position[1] = 0.0f; if (!hasIdentityMatrix()) { getMatrix().mapPoints(position); position[0] += mLeft; position[1] += mTop; ViewParent viewParent = mParent; while (viewParent instanceof View) { final View view = (View) viewParent; position[0] -= view.mScrollX; position[1] -= view.mScrollY; if (!view.hasIdentityMatrix()) { view.getMatrix().mapPoints(position); position[0] += view.mLeft; position[1] += view.mTop; viewParent = view.mParent; if (viewParent instanceof ViewRootImpl) { // *cough* final ViewRootImpl vr = (ViewRootImpl) viewParent; position[1] -= vr.mCurScrollY; location[0] = (int) (position[0] + 0.5f); location[1] = (int) (position[1] + 0.5f); }View.getLocationOnScreen(int[] location)
/** * p Computes the coordinates of this view on the screen. The argument * must be an array of two integers. After the method returns, the array * contains the x and y location in that order. /p * @param location an array of two integers in which to hold the coordinates public void getLocationOnScreen(int[] location) { getLocationInWindow(location); final AttachInfo info = mAttachInfo; if (info != null) { location[0] += info.mWindowLeft; location[1] += info.mWindowTop; }
Android | 音视频方向进阶路线及资源合集 但是系统相机和系统控件VideoView的局限性都是可定制型太差,系统相机的图像分辨率,视频码率以及VideoView的进度条等.
字节卷动 You will never know how excellent you are unless you impel yourself once.
相关文章
- Android人脸检测介绍
- Android基础面试常常死在这几个问题上,算法太TM重要了
- Android Paint类方法说明
- 我的Android进阶之旅------>Android中android:windowSoftInputMode的使用方法
- Android Recovery模式学习体会
- Android NDK 交叉编译C++代码生成.so共享库详细步骤
- 浅析android中handler与Message(一)
- Appium 使用android_uiautomator定位元素时报错: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
- Android主题切换
- [模拟Android微信]主界面
- Android Handler处理机制 ( 二 ) ——Handler,Message,Looper,MessageQueue
- Android之从Browser中打开本地的应用程序&微信检测是否有对应app
- Android中GsonFormat的安装及使用
- Android导入第三方类库
- Android 判断app是否在前台还是在后台运行
- 一款简单易用的 Toast 组件,支持 Android&iOS
- 我的Android进阶之旅------>Android百度地图定位SDK功能学习
- 我的Android进阶之旅------>Android知识图谱
- 我的Android进阶之旅------>Android关于ImageSpan和SpannableString的初步了解
- 我的Android进阶之旅------> Android在TextView中显示图片方法
- 我的Android进阶之旅------>解决如下错误failed to copy 'Settings2.apk' to '/system/app//Settings2.apk': Read-only
- 我的Android进阶之旅------>对Java中注释/**@hide*/的初步认识
- 我的Android进阶之旅------>Android如何去除GridView的按下或点击选中后的背景效果
- 我的Android进阶之旅------>Android中android:visibility 属性VISIBLE、INVISIBLE、GONE的区别
- 我的Android进阶之旅------>Android自定义窗口标题实例
- 我的Android进阶之旅------>Android用PopupWindow实现弹出菜单实例
- 我的Android进阶之旅------>Android利用Sensor(传感器)实现指南针功能
- 我的Android进阶之旅------>Android ListView 应用解析(使用ArrayAdapter,SimpleAdapter和SimpleCursorAdapter适配器)
- Android系统移植与调试之------->深入理解Android Sensor系统 (4.0)