【问题标题】:Android: fling detection on ListView with complex rowsAndroid:在具有复杂行的 ListView 上进行检测
【发布时间】:2010-11-20 23:26:10
【问题描述】:

亲爱的 Android 黑客,我将一个手势监听器附加到一个 ListView 上。 ListView 的行由一个 LinearView 和一些 TextViews 组成。不幸的是,当它在其中一个 TextViews 上启动时,没有检测到投掷:

<?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 上启动投掷时,一切正常,但是当我在底部的 TextView 上启动它时,什么也没有发生。它包含可编辑的文本,如果这可能是问题...如前所述,侦听器附加到 ListView 本身。

如果有人可以提供帮助,我会很高兴!

简·奥利弗

【问题讨论】:

    标签: android listview ontouchlistener


    【解决方案1】:

    您的可编辑 TextView 正在从 onTouch() 返回 true,从而阻止事件被视图层次结构更高的 LinearLayout 处理。

    没有什么可以阻止您将自定义 OnTouchListener 附加到您的 TextView 以覆盖它并将事件传递给您现有的 GestureDetector

    textView.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View arg0, MotionEvent ev) {             
            return gestureDetector.onTouchEvent(ev);
        }           
    };
    

    【讨论】:

    • 谢谢,这听起来很有希望。过几天我会试试这个。
    猜你喜欢
    • 2011-01-17
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多