【发布时间】:2015-04-22 22:47:56
【问题描述】:
我有一个ListView 有几行。每行包含 7 个 TextViews,它们对 onClick() 事件做出反应。
这一切都很好,但是当用户点击行的边缘时,没有TextView 捕获onClick() 事件,根视图 - LinearLayout - 突出显示。
这当然是正常行为,但由于单击此处没有任何反应,我不希望突出显示线性布局。
有什么方法可以禁用此行为但继续捕捉TextViews 上的onClick() 事件?
(onClick 监听器设置在适配器的 getView() 方法中)
这里是 xml 文件的一些摘录。正如人们所看到的,我尝试了一些方法,但它们不起作用。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:longClickable="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:id="@+id/listelement_weekoverview_tv_mo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="@drawable/weeklylist_rndrectangle"
android:gravity="center_horizontal"
android:singleLine="false"
android:textColor="@color/appcolor_red_base" />
...
</LinearLayout>
未点击版本 点击版本
【问题讨论】:
-
这听起来像个 hack,但您可以将行项目的背景设置为始终具有相同颜色的可绘制资源。
-
@Emmanuel 我尝试将其设置为 (aet)android:color/transparent 但这不起作用,我想保持透明。
-
您指定的颜色不是完全不透明的。颜色也不是可绘制的。你想使用state list drawable。