首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android Scrollview没有捕捉到长点击

Android Scrollview没有捕捉到长点击
EN

Stack Overflow用户
提问于 2012-06-22 10:17:41
回答 2查看 2.2K关注 0票数 3

正如标题中所说,我有一个滚动视图,它应该监听长点击,但没有捕捉到任何点击。当我按住滚动视图时,没有任何反应--没有日志,没有触觉反馈,也没有对话。

提前感谢!

JAVA:

代码语言:javascript
复制
...
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:

代码语言:javascript
复制
<?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>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-06-22 11:39:19

好吧,我从来没有找出我的问题的确切来源,但我怀疑它与scrollview自己滚动所需的侦听器之间存在某种冲突。

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

票数 7
EN

Stack Overflow用户

发布于 2014-04-14 17:34:09

看看ScrollView的OnTouchEvent吧。它特别允许您在scrollView注册运动事件时触发performClick()命令。似乎ScrollView会拦截所有的触摸事件,把它们当作运动事件,而不会让这些事件冒泡到任何父母身上。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11149404

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档