亲爱的 Android 黑客们,我将识别 flings 的 gestureListener 附加到 ListView。 ListView 的行由一个 LinearView 和一些 TextView 组成。不幸的是,当它在其中一个 TextViews 上启动时,未检测到 fling:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000000" >
<TextView
android:id="@+id/author"
android:textSize="14sp"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/date"
android:textSize="11sp"
android:textColor="#eeeeee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</LinearLayout>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:textColor="#333333"
android:paddingBottom="5dp"
android:textSize="14sp"
android:layout_weight="2"/>
</LinearLayout>
因此,当我在水平 LinearLayout 上启动 fling 时,一切正常,但是当我在底部的 TextView 上启动时,什么也没有发生。它包含可编辑的文本,如果这可能是问题的话……正如所说,监听器附加到 ListView 本身。
如果有人能提供帮助,我会很高兴!
简·奥利弗
最佳答案
您的可编辑 TextView 正在返回 true
来自 onTouch()
,阻止事件被 LinearLayout
处理更高的 View 层次结构。
没有什么能阻止您附加自定义 OnTouchListener
给你的TextView
覆盖它并将事件传递给您现有的 GestureDetector
.
textView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent ev) {
return gestureDetector.onTouchEvent(ev);
}
};
关于Android:在具有复杂行的ListView上进行fling检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4235577/