3

正如标题中所说,我有一个滚动视图应该监听长按,但没有捕捉到任何。当我握住滚动视图时,什么也没有发生——没有日志、没有触觉反馈和没有对话。

提前致谢!

爪哇:

...
ScrollView text_sv = (ScrollView) findViewById(R.id.text_sv);
    text_sv.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {

            MMMLogs.i("click", "long-click recognized");

            AlertDialog.Builder builder = new AlertDialog.Builder(_this);

            builder
            .setTitle(name)
            .setMessage(DHMenuStorage.notification)
            .setCancelable(false)
            .setNegativeButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();

            return true;
        }

    });
...

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >

<ScrollView
    android:id="@+id/text_sv"
    android:layout_width="match_parent"
    android:layout_height="75dp"
    android:hapticFeedbackEnabled="true"
    android:clickable="true"
    android:longClickable="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/Gray"
            android:focusable="false"
            android:gravity="center"
            android:padding="4dp"
            android:text="-- Dining Hall Name --"
            android:textColor="@color/Black"
            android:textSize="28dp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/note"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/Gray"
            android:focusable="false"
            android:gravity="center"
            android:padding="4dp"
            android:text="-- Special note here --"
            android:textColor="@color/Black"
            android:textSize="14dp"
            android:textStyle="normal" />
    </LinearLayout>
</ScrollView>

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="5dp" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

4

2 回答 2

8

好吧,我从未确定问题的确切来源,但我怀疑它与滚动视图自身滚动所需的侦听器存在某种冲突。

我通过在线性布局而不是滚动视图上设置完全相同的侦听器来解决这个问题。简单的。希望能帮助到你!

于 2012-06-22T03:39:19.073 回答
0

查看 ScrollView 的OnTouchEvent。它特别允许您在 scrollView 注册运动事件时触发 performClick() 命令。似乎 ScrollView 会拦截所有触摸事件,将它们视为运动事件,并且不会让事件像点击一样冒泡到任何父级。

这是有道理的。如果我正在触摸一个滚动视图,我可能希望它是对滚动视图内某些内容的点击,但我不希望它触发与滚动视图的父级相关的内容。

于 2014-04-14T09:34:08.913 回答