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 ...
随机推荐
- VMWare虚拟机端口转发
# VMWare虚拟机端口转发 虚拟机和宿主机共用主机IP对外提供服务,又不想提供给虚拟机独立IP,使用VM虚拟机提供的端口转发功能正合适. ### 端口转发--------------------- ...
- 跟着百度学PHP[17]-PHP扩展CURL的用法详解
实现的功能: 1.实现远程获取和采集内容2.实现PHP 网页版的FTP上传下载3.实现模拟登陆:去一个邮件系统,curl可以模拟cookies4.实现接口对接(API),数据传输等:通过一个平台发送短 ...
- lua语言介绍
什么是Lua Lua是一个小巧的脚本语言. 是巴西里约热内卢天主教大学(Pontifical Catholic University of Rio de Janeiro)里的一个研究小组,由Rober ...
- sign-up 签约注册
sign-up 搜索网络['sin,ʌp] n. 注册; 签约;
- Collection接口与Iterator接口
Collection接口的实现类跟Vector相似.要从实现了Collection接口的类的实例中取出保存在其中的元素对象,必须通过Collection接口的Iterator()方法,返回一个Iter ...
- Java1.0的AWT(旧AWT)和Java1.1以后的AWT(新AWT)有着很大的区别
Java1.0的AWT(旧AWT)和Java1.1以后的AWT(新AWT)有着很大的区别,新的AWT克服了旧AWT的很多缺点,在设计上有较大改进,使用也更方便,这里主要介绍新的AWT, 但在Java1 ...
- php视频教程
网址:http://www.php100.com/index.html
- (转)数据库ACID特性
转自:http://blog.csdn.net/shuaihj/article/details/14163713 隔离级别实现原理:http://www.cnblogs.com/wrencai/p/5 ...
- 【R】自定义描述统计函数-从均值到峰度偏度
data_show<-function(x) { n<-length(x) m<-mean(x) v<-var(x) s<-sd(x) me<-median(x) ...
- AutoMapper整理收集
http://www.cnblogs.com/jobs2/p/3503990.html http://www.cnblogs.com/1-2-3/p/AutoMapper-Best-Practice. ...