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 ...
随机推荐
- binutils工具集之---objdump
在嵌入式软件开发中,有时需要知道所生成的程序文件中的段信息以分析问题,或者需要查看c语言对应的汇编代码,此时,objdump工具就可以帮大忙了.obj——object dump:转储. #inclu ...
- CSDN日报20170217——《辞职信:写给我的“藤野先生”》
[程序人生] 辞职信:写给我的"藤野先生" 作者:马伟青 对于离职的事情,我想由衷的对你说声抱歉! 我不是一个不懂得感恩的人,也不是一个不忠诚的人,更不是一个不热爱工作的人.不管提 ...
- MySql Int 类型和 varchar类型进行比较。
今天遇到个比较奇葩的问题,简单讲就是在Mysql中进行查询的时候 在Where语句中使用的int类型的字段和Varchar类型的字段进行对比. 例如:我这有一张表: 表中的数据如下: 当我进行查询的时 ...
- flutter 环境
以下内容copy 于 https://www.cnblogs.com/lovelyYakir/p/7610396.html 原文请参考此 我只是做个记录 第一步:安装Git 你需要安装Git作为Flu ...
- Supervisord进程管理工具
进程管理工具Supervisord Posted on 2014/06/17 by admin Supervisord 上面已经介绍了Go目前是有两种方案来实现他的daemon,但是官方本身还不支持这 ...
- Softmatic ScreenLayers 将截图存为psd格式
Softmatic ScreenLayers 是 Mac 上的一款截图软件,它与众不同的地方是可以将截取的屏幕图片按PSD格式保存到本地,并且图片里的每一种元素都被单独放入一个独立的layer,比如M ...
- 网络I/O:Socket→RMI
★Socket Socket编程可能大家都很熟,所以就不多讨论了,只是说通过socket把数据保存到远端服务器或从网络socket读取数据也不失为一种值得考虑的方式. ★RMI RMI机制其实就是RP ...
- SQL Server Replace函数
REPLACE用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式. 语法REPLACE ( 'string_expression1' , 'string_expression2' ...
- git 入门一(初识)
分布式版本控制系统 & 集中式版本控制系统 分布式版本控制系统( Distributed Version Control System)在这类系统中,像 Git,Mercurial,Baz ...
- 【BZOJ】3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)
http://www.lydsy.com/JudgeOnline/problem.php?id=3394 裸的floyd.. #include <cstdio> #include < ...