TouchDelegate
- Parameters:
- bounds Bounds in local coordinates of the containing view that should be mapped to the delegate view
- delegateView The view that should receive motion events
public class TouchDelegateActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.touch_delegate); View parentView = findViewById(R.id.parent_layout); parentView.post(new Runnable() {
@Override
public void run() {
Rect delegateArea = new Rect();
ImageButton myButton = (ImageButton) findViewById(R.id.button);
myButton.setEnabled(true);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(TouchDelegateActivity.this,"click",Toast.LENGTH_SHORT).show();
}
}); myButton.getHitRect(delegateArea); // 在ImageButton边框的右边和底边扩展触摸区域
delegateArea.right += 200;
delegateArea.bottom += 200; TouchDelegate touchDelegate = new TouchDelegate(delegateArea, myButton); // Sets the TouchDelegate on the parent view, such that touches
// within the touch delegate bounds are routed to the child.
if (View.class.isInstance(myButton.getParent())) {
((View) myButton.getParent()).setTouchDelegate(touchDelegate);
}
}
});
}
}
2.布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"> <ImageButton android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:src="@drawable/icon" />
</RelativeLayout>
TouchDelegate的更多相关文章
- Android -- TouchDelegate
设计规定 Android4.0设计规定的有效可触摸的UI元素标准是48dp,这是一个用户手指能准确并且舒适触摸的区域. 如下图所示,你的UI元素可能小于48dp,图标仅有32dp,按钮仅有40dp,但 ...
- Android Touch(3)View的touchDelegate
作用: 基类View有个函数 public void setTouchDelegate(TouchDelegate delegate),给view内部的另一个view设置一个touch代理. 图中vi ...
- 使用android.view.TouchDelegate扩大View的触摸点击区域
Android4.0设计规定的有效可触摸的UI元素标准是48dp,转化为一个物理尺寸约为9毫米.7~10毫米,这是一个用户手指能准确并且舒适触摸的区域. 如下图所示,你的UI元素可能小于48dp,图标 ...
- Android View 事件分发机制 源码解析 (上)
一直想写事件分发机制的文章,不管咋样,也得自己研究下事件分发的源码,写出心得~ 首先我们先写个简单的例子来测试View的事件转发的流程~ 1.案例 为了更好的研究View的事件转发,我们自定以一个My ...
- 一种扩大View点击范围的方法
Rect rect = new Rect();mBt0.getHitRect(rect); rect.bottom += 400; TouchDelegate touchDelegate = new ...
- Android 触摸手势基础 官方文档概览
Android 触摸手势基础 官方文档概览 触摸手势检测基础 手势检测一般包含两个阶段: 1.获取touch事件数据 2.解析这些数据,看它们是否满足你的应用所支持的某种手势. 相关API: Moti ...
- Android touch事件处理流程
前面我们看了key事件的处理流程,相信大家对此已经有了新的认识,这篇文章我打算带领大家来看看稍微复杂些的touch 事件的处理流程.说它复杂是因为key事件本身就key down,up,long pr ...
- Android的Touch事件处理机制
Android的Touch事件处理机制比较复杂,特别是在考虑了多点触摸以及事件拦截之后. Android的Touch事件处理分3个层面:Activity层,ViewGroup层,View层. 首先说一 ...
- Cocos2dx 多点触控
1 最容易忽略的东西,对于ios平台,须得设置glView的属性: [__glView setMultipleTouchEnabled:YES]; 2 如果调用CCLayer的方法setTouchEn ...
随机推荐
- python学习之logging模块
Logger.setLevel(level) 设置记录器的级别为level.低于该级别的信息将被忽略. 记录器默认级别为NOTSET.如果记录器是根记录器,则默认将记录所有信息: 如果是一个非根记录器 ...
- ORACLE 中 TRANSLATE的用法
--TRANSLATE(string,from_str,to_str) --to_str和from_str中的字符一一对应 --如果string里有,from_str字符集里没有的字符,将保留 --如 ...
- 构建自己的embedded linux系统
[教程]使用buildroot完全自定义自己的embedded linux系统(nand)http://www.eeboard.com/bbs/thread-38377-1-1.html [教程] [ ...
- Supervisord常见用法和介绍
Supervisord是用Python实现的一款非常实用的进程管理工具.supervisord会帮你把管理的应用程序转成daemon程序,而且可以方便的通过命令开启.关闭.重启等操作,而且它管理的进程 ...
- Centos6.X 安装MongoDb
1.查看linux版本,之所以查看linux版本,是因为centos7和以前版本用的防火墙不一样,安装完mongodb后,需要关闭防火墙(或者其他方法,专业运维人员使用,我们这里为简单,直接关闭即可) ...
- 去掉点击map时的显示area边框
cus="true"的属性即可 如下: <img src="some.jpg" border="0" usemap="#ma ...
- 【转】【CTO俱乐部走进支付宝】探索支付宝背后的那些技术 部分
怎么避免研发环节当中引入漏洞?“我们有一套比较成熟的安全研发开发框架.首先我们用统一的框架,框架本身是经过我们安全工程师去做过非常好的认证的,同时在研发过程当中我们对这些问题也有些规范.一旦发现风险我 ...
- lstrcpyn
看代码时遇到的一些不会用的函数,记录下来. 1. lstrcpyn LPTSTR lstrcpyn( __out LPTSTR lpString1, __in LPCTSTR lpString2, _ ...
- 进度条在.net导入Excel时的应用实例
这篇文章主要介绍了进度条在.net导入Excel时的应用,以实例形式讲述了.net导入Excel时根据页面情况显示进度条的实现方法,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了进度条在.ne ...
- 网站速度优化模块HttpCompressionModule
为了优化网站的访问速度,准备采用HttpCompressionModule 6对传输数据进行压缩,下载了HttpCompressionModule 6 , 并按照示例程序中的web.config配置了 ...