我有一個自定義列表視圖,其中添加了幾個元素,如ImageView
,TextView
和View
。這三個部分組成了一個單行,我想將這整個clickable
。目前發生的事情是當我把android:background="@drawable/text_selection_file"
設置爲ImageView
或TextView
時,它只選擇相應的元素背景,而不是整行。由於我有多於一行,所以我不能將每行插入到不同的GroupView
中,因此每個下一行android:layout_below="above_view"
的屬性都不起作用。所以我需要找到一種方法來做到這一點,我可以選擇整行。目前它只適用於TextView
或ImageView
的特定選擇,但不能同時選擇兩者。我對XML
代碼如下在Android中設置自定義行
CODE
//Above code for layout
<ImageView
android:id="@+id/homeLink"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_below="@+id/menu_view"
android:layout_margin="8dp"
android:contentDescription="@string/app_name"
android:gravity="center_vertical"
android:src="@drawable/home" />
<TextView
android:id="@+id/home_link"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_below="@+id/menu_view"
android:layout_marginLeft="45dp"
android:gravity="center_vertical"
android:text="Home"
android:textColor="@color/WHITE"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:id="@+id/home_view"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="@+id/home_link"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@color/VIEW_COLOR" />
//More rows down there
檢查)當你點擊列表行集中。如果是這樣的話,將它添加到imageview android:focusable =「false」 android:focusableInTouchMode =「false」' – Raghunandan
ImageView和TextView單擊時單獨聚焦! – Saqib