且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何禁用触摸屏的Andr​​oid手机?

更新时间:2023-02-26 21:39:13

修改

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

You can do it by implementing a custom extension of ListView which you set as the list to use in your XML file. Then in your CustomListView, implement the onTouchEvent method and only call super.onTouchEvent if you want the touch to be processed by the list. Here's what I mean:

有话这种影响在包含列表中的布局文件。

Have something to this effect in the layout file that contains your list.

<com.steve.CustomListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/start_menu_background"
    android:cacheColorHint="#00000000"
    android:id="@android:id/list">
</com.steve.CustomListView>

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

Then have a custom class like this:

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;
        }
    }
}

这code将只允许触摸事件得到由ListView的处理,如果他们在屏幕上方100像素。显然,替换if语句的东西更适合您的应用程序。也不要在日志报表离开一旦你得到它的工作,因为你将自己的垃圾邮件数以百计的每个手势后,记录线;他们只有自己做出明显发生了什么。

This code will only allow touch events to get processed by the ListView if they're in the top 100 pixels of the screen. Obviously, replace that if statement with something more appropriate for your application. Also don't leave in the Log statements once you've got it to work since you'll spam yourself with hundreds of logging lines after each gesture; they're only their to make obvious what is happening.