【发布时间】:2011-11-17 12:03:29
【问题描述】:
是否可以使ListView 项目的选择颜色显示带阴影(例如在左侧)。
我希望左侧的列表项比右侧的更轻。
【问题讨论】:
-
是的,它可能使用选择器和使用矩形drawble对它们进行一些研发,你会得到答案
标签: android listview formatting
是否可以使ListView 项目的选择颜色显示带阴影(例如在左侧)。
我希望左侧的列表项比右侧的更轻。
【问题讨论】:
标签: android listview formatting
pressed_gradient.xml:(R.drawable.pressed_gradient)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ffffff"
android:centerColor="#ff0000"
android:endColor="#000000"
android:angle="270" />
</shape>
listview_selector.xml:(R.drawable.listview_selector)
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Pressed -->
<item
android:state_pressed="true"
android:drawable="@drawable/pressed_gradient" />
</selector>
现在在你的 xml 中使用:
<ListView
...
android:listSelector="@drawable/listview_selector"
...
/>
【讨论】: