无法在android Emulator中显示listview样式

时间:2014-05-29 10:29:47

标签: android android-listview android-emulator

以下是代码:

我编写的代码与此类似:

listview normal and hover background style in android

但我在SDK中获取视图: 喜欢颜色和分隔符

但这个输出我没有进入模拟器

模拟器的输出是: 我没有在模拟器中获得任何颜色或分隔符

 <ListView
        android:id="@+id/lstpass"
        android:layout_width="fill_parent"
        android:layout_height="500dp"
        android:textColor="#000000"
        android:cacheColorHint="#000000"
        android:dividerHeight="10dp"
        android:divider="@drawable/listbackimage"
        android:layout_weight="5"
        android:listSelector="@drawable/list_selector"
        tools:listitem="@android:layout/simple_list_item_1"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_gravity="top" />

list_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/gradient_bg" />
    <item android:state_pressed="true"
        android:drawable="@drawable/gradient_bg_hover" />
    <item android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/gradient_bg_hover" />
</selector>

gradient_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#e8eef4"
        android:centerColor="#fdfdfd"
        android:endColor="#d3dfe8"
        android:angle="270" />
    <stroke android:width="1dp" android:color="#b7ccdd" />
    <padding android:left="6dp" android:top="6dp" android:right="6dp"
        android:bottom="6dp" />
    <margin android:left="15dp" android:top="15dp" android:right="15dp"
        android:bottom="15dp" />
    <corners android:radius="4dp" />
</shape>

gradient_bg_hover.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#ffe181"
        android:centerColor="#f5cd4a"
        android:endColor="#e8c34e"
        android:angle="270" />
    <stroke android:width="1dp" android:color="#e3b52c" />

    <padding android:left="6dp" android:top="6dp" android:right="6dp"
        android:bottom="6dp" />
    <margin android:left="15dp" android:top="15dp" android:right="15dp"
        android:bottom="15dp" />
    <corners android:radius="4dp" />
</shape>

等待你的宝贵答案..

提前致谢

1 个答案:

答案 0 :(得分:0)

这是我用的

<强> main_activity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/lstpass"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_gravity="top"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_weight="5"
        android:cacheColorHint="#000000"
        android:dividerHeight="10dp"
        android:listSelector="@drawable/list_selector"
        android:textColor="#000000" />

</LinearLayout>

<强> gradient_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#e8eef4"
        android:centerColor="#fdfdfd"
        android:endColor="#d3dfe8"
        android:angle="270" />
    <stroke android:width="1dp" android:color="#b7ccdd" />
    <padding android:left="6dp" android:top="6dp" android:right="6dp"
        android:bottom="6dp" />
    <margin android:left="15dp" android:top="15dp" android:right="15dp"
        android:bottom="15dp" />
    <corners android:radius="4dp" />
</shape>

<强> gradient_bg_hover.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#ffe181"
        android:centerColor="#f5cd4a"
        android:endColor="#e8c34e"
        android:angle="270" />
    <stroke android:width="1dp" android:color="#e3b52c" />

    <padding android:left="6dp" android:top="6dp" android:right="6dp"
        android:bottom="6dp" />
    <margin android:left="15dp" android:top="15dp" android:right="15dp"
        android:bottom="15dp" />
    <corners android:radius="4dp" />
</shape>

<强> list_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/gradient_bg" />
    <item android:state_pressed="true"
        android:drawable="@drawable/gradient_bg_hover" />
    <item android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/gradient_bg_hover" />
</selector>

这就是我得到的输出,是你需要的吗?

普通视图

Normal ListView

悬停视图

Hover ListView