我想改变ListView
分隔线的颜色。 任何帮助,将不胜感激。
您可以使用android:divider="#FF0000"
在布局xml文件中设置此值。 如果您正在更改颜色/绘图,则必须设置/重置分隔线的高度。
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:divider="#FFCC00" android:dividerHeight="4px"/> </LinearLayout>
或者你可以编码:
int[] colors = {0, 0xFFFF0000, 0}; // red for the example myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors)); myList.setDividerHeight(1);
希望能帮助到你
对于单色线使用:
list.setDivider(new ColorDrawable(0x99F10529)); //0xAARRGGBB list.setDividerHeight(1);
DividerHeight设置在divider之后是很重要的 ,否则你什么也得不到。
您还可以使用以下方法从您的资源中获取颜色:
dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight))); dateView.setDividerHeight(1);
XML版本为@Asher Aslan酷效果。
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="https://schemas.android.com/apk/res/android" > <gradient android:angle="180" android:startColor="#00000000" android:centerColor="#FFFF0000" android:endColor="#00000000"/> </shape>
该形状的名称为:在drawable文件夹下的list_driver.xml
<ListView android:id="@+id/category_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:divider="@drawable/list_driver" android:dividerHeight="5sp" />
有两种方法可以做同样的事情:
在你的xml文件中使用下面的代码
<ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="#000000" android:dividerHeight="1dp"> </ListView>
对于ListView使用android:divider="#FF0000"
和android:dividerHeight="2px"
。
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:divider="#0099FF" android:dividerHeight="2px"/>
以上就是android开发分享如何更改Android ListView分隔线的颜色?相关内容,想了解更多android开发(异常处理)及android游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/addevelopment/517011.html