Android:在具有复杂行的ListView上进行fling检测

标签 android listview ontouchlistener

亲爱的 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/

相关文章:

android - ViewPager 拦截所有 x 轴 onTouch 事件。如何禁用?

android - 拖放 ImageView 不起作用

android - 在 Android 平板电脑中浏览 USB 设备中的文件

java - Android中如何判断数据库是否需要升级?

android - 适用于不同屏幕尺寸的Android Apk Split

android - 如何在操作栏中制作带有通知数量的图标?

WPF。如果ListView为空,ListView消失

android - 更新 ListView 内的 ImageView

java - 在 onTouchListener 中设置宽度

android - 如何以编程方式查看 android listView 快速滚动拇指?