我有以下代碼:側面相對佈局中的線性佈局我想更改按下時相對佈局的顏色。
選擇代碼:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape>
<solid android:color="@color/red" />
</shape></item>
</selector>
佈局代碼:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/itemLayoutView"
android:layout_width="match_parent"
android:layout_height="70dp"
android:clickable="true"
android:background="@drawable/listview_row_background_selector"
android:paddingLeft="@dimen/list_view_layout_margin" >
<LinearLayout
android:id="@+id/itemLinearLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:clickable="true"
android:orientation="vertical" >
<TextView
android:id="@+id/gameNameView"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:textSize="@dimen/game_list_text_size" />
<TextView
android:id="@+id/gameCreationDateView"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:textColor="@color/gray"
android:textSize="@dimen/small_text_size"
android:textStyle="italic" />
</LinearLayout>
</RelativeLayout>
我想改變相對佈局的顏色,當我點擊它。但是,上面的代碼不起作用。
有什麼建議嗎?
注:我在我的列表視圖中使用佈局作爲代碼的一部分。
我不能我有我自己的自定義偵聽器的列表查看所以列表視圖選擇不起作用。 –
真的是你喜歡做什麼。你能簡單解釋我嗎? –
好吧,我將我自己的自定義偵聽器添加到相對視圖的列表視圖行中,以實現向左滑動和向右滑動等功能。我注意到,點擊ListView後添加監聽器不會再改變listview項目的背景。所以我想我必須將它添加到RelativeLayout,它是列表視圖中包含的元素。 –