Android 根据坐标获取控件方法
来源:互联网 发布:管理wifi软件 编辑:程序博客网 时间:2024/05/14 22:40
http://www.2cto.com/kf/201501/370226.html
http://www.2cto.com/kf/201501/370226.html
http://www.2cto.com/kf/201501/370226.html
http://www.2cto.com/kf/201501/370226.html
- Android 根据坐标获取控件方法
<iframe id="iframeu2597680_0" src="http://pos.baidu.com/lcbm?sz=650x180&rdid=2597680&dc=2&di=u2597680&dri=0&dis=0&dai=4&ps=329x96&coa=at%3D3%26rsi0%3D650%26rsi1%3D180%26pat%3D1%26tn%3DbaiduCustNativeAD%26rss1%3D%2523F9F9F9%26conBW%3D0%26adp%3D1%26ptt%3D0%26titFF%3D%2525E5%2525BE%2525AE%2525E8%2525BD%2525AF%2525E9%25259B%252585%2525E9%2525BB%252591%26titFS%3D14%26rss2%3D%2523000000%26titSU%3D0%26tft%3D0%26tlt%3D1%26ptbg%3D90%26piw%3D140%26pih%3D90%26ptp%3D1&dcb=BAIDU_SSP_define&dtm=HTML_POST&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1475034420591&ti=Android%20%E6%A0%B9%E6%8D%AE%E5%9D%90%E6%A0%87%E8%8E%B7%E5%8F%96%E6%8E%A7%E4%BB%B6%E6%96%B9%E6%B3%95%20-%20Android%E7%A7%BB%E5%8A%A8%E5%BC%80%E5%8F%91%E6%8A%80%E6%9C%AF%E6%96%87%E7%AB%A0_%E6%89%8B%E6%9C%BA%E5%BC%80%E5%8F%91%20-%20%E7%BA%A2%E9%BB%91%E8%81%94%E7%9B%9F&ari=2&dbv=2&drs=1&pcs=1153x587&pss=1153x340&cfv=0&cpl=5&chi=1&cce=true&cec=GBK&tlm=1473529717&rw=587&ltu=http%3A%2F%2Fwww.2cto.com%2Fkf%2F201501%2F370226.html&ltr=http%3A%2F%2Fwww.2cto.com%2Fkf%2F201501%2F370226.html&ecd=1&psr=1280x800&par=1280x705&pis=-1x-1&ccd=24&cja=false&cmi=7&col=zh-CN&cdo=-1&tcn=1475034422&qn=b34d350ff5a95cdb&tt=1475034419816.1906.2300.2301" width="650" height="180" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="border-width: 0px; border-style: initial; vertical-align: bottom; margin: 0px;"></iframe>
- 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
/**
* 根据坐标获取相对应的子控件<br>
* 在Activity使用
*
* @param x坐标
* @param y坐标
* @return 目标View
*/
public
View getViewAtActivity(
int
x,
int
y) {
// 从Activity里获取容器
View root = getWindow().getDecorView();
return
findViewByXY(root, x, y);
}
/**
* 根据坐标获取相对应的子控件<br>
* 在重写ViewGroup使用
*
* @param x坐标
* @param y坐标
* @return 目标View
*/
public
View getViewAtViewGroup(
int
x,
int
y) {
return
findViewByXY(
this
, x, y);
}
private
View findViewByXY(View view,
int
x,
int
y) {
View targetView =
null
;
if
(view
instanceof
ViewGroup) {
// 父容器,遍历子控件
ViewGroup v = (ViewGroup) view;
for
(
int
i =
0
; i < v.getChildCount(); i++) {
targetView = findViewByXY(v.getChildAt(i), x, y);
if
(targetView !=
null
) {
break
;
}
}
}
else
{
targetView = getTouchTarget(view, x, y);
}
return
targetView;
}
private
View getTouchTarget(View view,
int
x,
int
y) {
View targetView =
null
;
// 判断view是否可以聚焦
ArrayList<view> TouchableViews = view.getTouchables();
for
(View child : TouchableViews) {
if
(isTouchPointInView(child, x, y)) {
targetView = child;
break
;
}
}
return
targetView;
}
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
;
}
</view>
0 0
- Android 根据坐标获取控件方法
- Android 根据坐标获取控件方法
- android获取控件坐标
- Android 根据坐标获取地址
- android 根据坐标获取RGB
- android根据坐标获取相应控件,判断点是否在控件上
- android控件获取屏幕坐标
- Android获取View坐标方法
- Android中获取坐标方法
- android 获取坐标的方法
- 各种获取控件坐标的方法总结
- Android之获取控件的坐标
- Android如何获取子控件位置坐标
- Android 获取控件的坐标位置
- Android获取控件坐标,触摸点坐标 getX getRawX
- Android根据坐标判断是否在控件内
- Android获取控件坐标为0的原因及取得控件位置和两控件距离的方法
- Android根据已知的经纬度坐标获取当前位置
- test
- oracle 分组查询 子查询 统计查询 FROM加子查询临时表 查询高于平均工资 示例代码
- javascript的面向对象 函数 闭包 构造函数 继承
- UVA 1382 Distant Galaxy(枚举优化)
- 泛型浅析
- Android 根据坐标获取控件方法
- 注入(2)--APC(Asynchronous Procedure Call)注入(异步过程调用)
- leetcode 300 Longest Increasing Subsequence
- visual studio配置openGL
- android获得控件在屏幕中的绝对坐标
- 求阶乘和
- 堆栈溢出及其原因
- 注入(1)--注册表注入
- 【CDP-云设计模式】第8章,3.工作观察者模式(Job Observer Pattern)