android 禁用触摸屏,如何在Android手机中禁用触摸屏?

编辑

您可以通过实现ListView控件的自定义扩展已设为列表中的XML文件中使用做到这一点。然后在你的CustomListView中,实现onTouchEvent方法,如果你想让列表处理触摸,只调用super.onTouchEvent。这就是我的意思:

在包含您的列表的布局文件中有这种效果。

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/start_menu_background"

android:cacheColorHint="#00000000"

android:id="@android:id/list">

然后有一个自定义类这样的:

public class CustomListView extends ListView {

Context mContext;

public CustomListView (Context context, AttributeSet attrs){

super(context, attrs);

mContext = context;

}

public boolean onTouchEvent(MotionEvent event){

if (event.getRawY() < 100){

Log.d("Your tag", "Allowing the touch to go to the list.");

super.onTouchEvent(event);

return true;

} else {

Log.d("Your tag", "Not allowing the touch to go to the list.");

return true;

}

}

}

此代码将只允许触摸事件由ListView控件,如果他们在屏幕顶部100像素得到处理。很明显,将if语句替换为更适合您的应用程序的东西。一旦你使用Log语句,也不要在Log语句中留下,因为你会在每次手势之后用数百条日志记录行向你发送垃圾邮件;他们只是为了明确发生了什么。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值