博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android – Using TouchDelegate
阅读量:6000 次
发布时间:2019-06-20

本文共 1874 字,大约阅读时间需要 6 分钟。

      TouchDelegates in Android allow to increase the touch area of a View, e.g. Button. This is very useful if you want to make it easier for the user to touch your button.

      Here is a small example for the usage of a touch delegate. The layout has the ID root and contains a button with the ID delegated_button.

      

kage de.vogella.android.touchdelegate; import android.app.Activity;import android.graphics.Rect;import android.os.Bundle;import android.view.TouchDelegate;import android.view.View;import android.widget.Button; public class MainActivity extends Activity {    private Button mButton;     /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        mButton = (Button) findViewById(R.id.delegated_button);        View parent = findViewById(R.id.root);        parent.post(new Runnable() {            public void run() {                // Post in the parent's message queue to make sure the parent                // lays out its children before we call getHitRect()                Rect delegateArea = new Rect();                Button delegate = mButton;                delegate.getHitRect(delegateArea);                delegateArea.top -= 600;                delegateArea.bottom += 600;                delegateArea.left -= 600;                delegateArea.right += 600;                TouchDelegate expandedArea = new TouchDelegate(delegateArea,                        delegate);                // give the delegate to an ancestor of the view we're                // delegating the                // area to                if (View.class.isInstance(delegate.getParent())) {                    ((View) delegate.getParent())                            .setTouchDelegate(expandedArea);                }            };        });    }

转载地址:http://hxwmx.baihongyu.com/

你可能感兴趣的文章
WebStorm 配置less
查看>>
Oracle 安装报错 [INS-06101] IP address of localhost could not be determined 解决方法输入日志标题...
查看>>
项目开发中如何设计表
查看>>
Maven启用代理访问
查看>>
LDAP & Implementation
查看>>
Codeigniter处理用户登录验证后URL跳转
查看>>
正则表达说明—Pattern API
查看>>
查询数据库中的表格---通过构造方法将数据存入到List集合中---遍历进行输出
查看>>
consul部署多台Docker集群
查看>>
威佐夫博奕(二)
查看>>
$(function(){})的执行过程分析
查看>>
hdu 4597 Play Game
查看>>
hdu 1398 Square Coins (母函数)
查看>>
试验性的Numpy教程(译)
查看>>
ecshop调用显示购物车商品数量
查看>>
Hbase之缓存扫描加快读取速度
查看>>
twitter storm 源码走读之5 -- worker进程内部消息传递处理和数据结构分析
查看>>
CCF 201503-4 网络延时
查看>>
070101_描述性统计(均值,中位数,众数,方差,标准差,与常见的统计图表)...
查看>>
JAVA调用shell脚本利用ansible修改多节点上的redis参数
查看>>