我有一个listView。 ListView的每一行/项包含2个视图 TextView 和 ImageView 。我希望只有 ImageView可以聚焦和点击,而textView不应该是可聚焦和可点击的。
Eachrow.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textViewEachBlockedKeyword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Keyword"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/imageViewBlockKeywordDelete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3.1"
android:layout_marginLeft="2dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:src="@drawable/delete" />
</LinearLayout>
怎么做? 感谢
答案 0 :(得分:0)
像这样修改你的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textViewEachBlockedKeyword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Keyword"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:clickable="false"
android:focusable="false" />
<ImageView
android:id="@+id/imageViewBlockKeywordDelete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3.1"
android:layout_marginLeft="2dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:src="@drawable/delete"
android:clickable="true"
android:focusable="true" />
</LinearLayout>
答案 1 :(得分:0)
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
将此添加到textview标记
答案 2 :(得分:0)
尝试以下代码只需将imageview更改为imagebutton
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textViewEachBlockedKeyword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Keyword"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageButton
android:id="@+id/imageViewBlockKeywordDelete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3.1"
android:layout_marginLeft="2dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:src="@drawable/delete" />
</LinearLayout>