如何改变在ListView分频器颜色? [英] How to change the divider color in the listview?

查看:145
本文介绍了如何改变在ListView分频器颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要改变在ListView分频器的颜色。在code我使用做到这一点是引用如下:

 <的ListView
        机器人:ID =@ + ID / restaurant_list_widget
        机器人:layout_width =1像素
        机器人:layout_height =1像素
        机器人:layout_weight =1机器人:背景=@可绘制/列表
        机器人:分隔=#FFFFFF
        机器人:dividerHeight =递四方>
    < / ListView控件>
 

我还得到一个黑色的1像素宽的护栏。我究竟做错了什么?

更新:列表项

 < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:方向=垂直
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
  机器人:填充=5DP
  机器人:背景=@色/ list_background
  >
  < TextView的机器人:ID =@ + ID / restaurant_list_item_name机器人:layout_marginBottom =4DP机器人:TEXTSTYLE =黑体的Andr​​oid版本:TEXTSIZE =15dp机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT机器人:文字颜色=#FFF机器人:文本=餐厅的名称放这里>< / TextView的>
  < TextView的机器人:ID =@ + ID / restaurant_list_item_detail机器人:TEXTSIZE =10dp机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT>< / TextView的>
< / LinearLayout中>
 

解决方案

我已经尝试过用:

 <的ListView
    机器人:ID =@ + ID / ListView01
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:分隔=@色/ redBackground
    机器人:dividerHeight =1dip>
 < / ListView控件>
 

和颜色值里面colors.xml:

 <颜色名称=redBackground>#C60202< /彩色>
 

和它的做工精细,并显示分频器颜色为红色与1dip高度。

更新:

只是检查您的列表视图的布局,你提到1px的为 layout_width layout_height ,并要设置4PX的 dividerHeight

I need to change the divider color in the listview. The code I am using to accomplish this is quoted below:

 <ListView
        android:id="@+id/restaurant_list_widget"
        android:layout_width="1px"
        android:layout_height="1px"
        android:layout_weight="1" android:background="@drawable/list"
        android:divider="#FFFFFF"
        android:dividerHeight="4px">
    </ListView>  

I still get a black 1px wide divider. What am I doing wrong?

Update: ListItem

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:padding="5dp"
  android:background="@color/list_background"
  >
  <TextView android:id="@+id/restaurant_list_item_name" android:layout_marginBottom="4dp" android:textStyle="bold" android:textSize="15dp" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="#fff" android:text="Restaurant Name Goes Here"></TextView>
  <TextView android:id="@+id/restaurant_list_item_detail" android:textSize="10dp" android:layout_width="fill_parent" android:layout_height="fill_parent"></TextView>    
</LinearLayout>

解决方案

I have tried it out with:

 <ListView 
    android:id="@+id/ListView01" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="@color/redBackground"
    android:dividerHeight="1dip">
 </ListView>

and color value is inside colors.xml:

<color name="redBackground">#C60202</color>

And its working fine and displaying Divider color as red with 1dip height.

Update:

Just check your listview layout, you have mentioned 1px for layout_width and layout_height and you are setting 4px for the dividerHeight.

这篇关于如何改变在ListView分频器颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆