触摸时更改列表视图行内的背景颜色和视图颜色

时间:2013-04-09 19:49:27

标签: android listview view

我需要将行视图背景颜色更改为蓝色,它是这样的: enter image description here

xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="@dimen/main_info_cell_view_width"
android:layout_height="@dimen/main_info_cell_view_height"
android:background="@color/main_info_cell_background_color" >

<FrameLayout
    android:id="@+id/pic_frame"
    android:layout_width="@dimen/channel_pic_background_widht"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true" >

    <View
        android:id="@+id/channel_pic_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/main_info_cell_pic_background_color" />

    <ImageView
        android:id="@+id/channel_pic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/c__no_image" />
</FrameLayout>

<View
    android:id="@+id/divider"
    android:layout_width="@dimen/main_info_cell_divider_widht"
    android:layout_height="match_parent"
    android:layout_toRightOf="@+id/pic_frame"
    android:background="@color/main_info_cell_divider_color" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/title_margin_left"
    android:layout_marginRight="@dimen/title_margin_right"
    android:layout_marginTop="@dimen/title_margin_top"
    android:layout_toRightOf="@+id/divider"
    android:ellipsize="end"
    android:lines="2"
    android:textColor="@color/main_info_cell_title_color"
    android:textSize="@dimen/title_text_size" />

<TextView
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="@dimen/time_margin_bottom"
    android:layout_marginLeft="@dimen/time_margin_left"
    android:layout_toRightOf="@+id/divider"
    android:textColor="@color/main_info_cell_time_color"
    android:textSize="@dimen/time_text_size" />

<TextView
    android:id="@+id/pos_number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="@dimen/pos_nr_margin_right"
    android:textColor="@color/main_info_cell_pos_nr_color"
    android:textSize="@dimen/pos_nr_size" />

</RelativeLayout>

我尝试使用行的选择器,但问题是选择器只更改视图的背景颜色,ImageView下面的黑色方块仍然保持黑色,如何更改其颜色以及行背景?

1 个答案:

答案 0 :(得分:3)

使用StateListDrawable作为层次结构的根/父ViewGroup的背景。

因此,android:background="@drawable/mystatelistdrawable"其中mystatelistdrawable是使用this guide布置的文件。

您可能还想查看android:duplicateParentState

相关问题