【问题标题】:ListView item's selection color with shading带阴影的 ListView 项目选择颜色
【发布时间】:2011-11-17 12:03:29
【问题描述】:

是否可以使ListView 项目的选择颜色显示带阴影(例如在左侧)。

我希望左侧的列表项比右侧的更轻。

【问题讨论】:

  • 是的,它可能使用选择器和使用矩形drawble对它们进行一些研发,你会得到答案

标签: android listview formatting


【解决方案1】:

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"
  ...
/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 2011-12-19
    相关资源
    最近更新 更多