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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作