【问题标题】:RelativeLayout over ListView, onclick not detected when RealtiveLayout is shown as在 ListView 上的 RelativeLayout,当 RealtiveLayout 显示为时未检测到 onclick
【发布时间】:2012-06-18 10:00:01
【问题描述】:

我目前是relative layout,显示在listview。原来,当我点击RelativeLayout时,总是会在list view中捕获点击事件。

我想在布局显示时检测一个手势,但是当我单击时,该项目是从下方的listview 中选择的。

有人知道这个问题的解决方案吗?

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

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

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="0dp" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="-4dp"
            android:layout_weight="0" />
    </LinearLayout>
</TabHost>

    <RelativeLayout
        android:id="@+id/playertab1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/back_artista"
        android:gravity="center_vertical|left"
        android:paddingLeft="15dp" >

        <LinearLayout
            android:id="@+id/music_info"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity=""
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/artist_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="9dp"
                android:layout_marginTop="4dp"
                android:src="@drawable/placeholder" />

            <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/playlist_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="playlist_name"
                    android:textColor="#3BBEF9"
                    android:textSize="15dp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/artist_album"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="artist_album"
                    android:textColor="#EEEEEE"
                    android:textSize="11dp" />

                <TextView
                    android:id="@+id/artist_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="artist_album"
                    android:textColor="#EEEEEE"
                    android:textSize="11dp" />

                <TextView
                    android:id="@+id/artist_song"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="artist_song"
                    android:textColor="#EEEEEE"
                    android:textSize="11dp" />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>

被插入的列表视图:

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="0dp" />

【问题讨论】:

    标签: android android-listview android-relativelayout android-tabhost android-framelayout


    【解决方案1】:

    如果您使用GestureDetector,请先尝试调用mDetector.setIsLongpressEnabled(true);,然后通过convertView.setLongClickable(true); 设置可长按的视图

    【讨论】:

    • 当我在不与列表视图重叠的区域做出手势时,会正确检测到手势。但是手势必须在与listview重叠的RelativeLayout中进行,当我点击任何重叠的区域时,listview始终是检测到的元素...
    • 尝试将GestureDetector 应用于ListViewRelativeLayout 下方的布局。例如,您可以使用findViewById(android.R.id.content);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多