ssummeraw 2013-03-01 03:29 采纳率: 10%
浏览 3283
已采纳

创建一个自定义的 ListView selector

当我点击一个 listview item 时,为什么没有 selector 出现?
帖下我的代码:
ListView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/streamRelativeLayout">
    <ListView android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/streamListView" android:cacheColorHint="#00000000" android:fadingEdge="none" android:listSelector="@drawable/swipeview_list_selector">   </ListView>
    <TextView android:layout_centerInParent="true" android:layout_height="wrap_content" android:id="@+id/noStreamTextView" android:layout_width="wrap_content" android:text="No Stream Available" android:visibility="invisible"></TextView>
    <ProgressBar android:layout_centerInParent="true" android:layout_height="wrap_content" android:id="@+id/streamProgressBar" android:layout_width="wrap_content"></ProgressBar>
</RelativeLayout>

my selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_enabled="false" android:state_focused="true"
        android:drawable="@drawable/stocks_gradient" />
  <item android:state_pressed="true"
        android:drawable="@drawable/stocks_gradient" />
  <item android:state_focused="true"
        android:drawable="@drawable/stocks_gradient" />
</selector>

gradient:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#ECECEC"
        android:centerColor="#F6F6F4"
        android:endColor="#F8F8F6"
        android:angle="90"
        android:dither="true"
     />
</shape>

我同时也在 getView()里设置了颜色转换

int colorPos = position % colors.length;
            v.setBackgroundColor(colors[colorPos]);
  • 写回答

2条回答 默认 最新

  • Baby_Bonnie 2013-03-01 05:30
    关注

    需要设置 selectorontop 属性为 true

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)