编辑

您可以通过实现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语句中留下,因为你会在每次手势之后用数百条日志记录行向你发送垃圾邮件;他们只是为了明确发生了什么。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐