ListView Selected Row Android

时间:2013-12-17 03:15:28

标签: android listview

我有以下视图,对于listview控件中的每一行都是膨胀的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:background="@drawable/rounded_row"
              android:padding="5dp"
    >

对于listview本身,我将list_selecter设置为此文件:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_selector_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/list_selector_focused" android:state_focused="true"/>

rounded_row的xml:

 <?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#000"/>

    <stroke android:width="3dp"
            android:color="#fff"
        />

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"
        />

    <corners android:bottomRightRadius="7dp"
             android:bottomLeftRadius="7dp"
             android:topLeftRadius="7dp"
             android:topRightRadius="7dp"/>
</shape>

和list_selected_pressed的xml是

 <?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#fff"/>

    <stroke android:width="3dp"
            android:color="#ccc"
        />

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"
        />

    <corners android:bottomRightRadius="7dp"
             android:bottomLeftRadius="7dp"
             android:topLeftRadius="7dp"
             android:topRightRadius="7dp"/>
</shape>

list_focused

    <?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFEBCD"/>

    <stroke android:width="3dp"
            android:color="#FFFF00"
        />

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"
        />

    <corners android:bottomRightRadius="7dp"
             android:bottomLeftRadius="7dp"
             android:topLeftRadius="7dp"
             android:topRightRadius="7dp"/>
</shape>

故意,我改变了笔触颜色。当我按下list_view_row以查看圆形边框颜色从白色变为灰色时,我期待的问题。我根本没有看到这一点。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

请将list_selecter应用到list_row而不是list_view