-1

我有一个列表视图。ListView 的每一行/项目包含 2 个视图,一个 TextView和一个ImageView。我希望只有ImageView 可以是可聚焦和可点击的,而 textView 不应该是可聚焦和可点击的。

每个行.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>

这个怎么做 ?谢谢

4

3 回答 3

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>
于 2013-02-20T09:32:11.827 回答
0
 android:focusable="false"
   android:focusableInTouchMode="false"
   android:clickable="false"

将此添加到您的 textview 标签

于 2013-02-20T09:33:20.513 回答
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>
于 2013-02-20T09:34:05.330 回答