`
zl4393753
  • 浏览: 333372 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

填充Listview第一个Item的分隔线

阅读更多
1. 在res/drawable/目录下新建 mygradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle" >
	<gradient
		android:startColor="#282828"
		android:centerColor="#808080"
		android:endColor="#282828"
		android:angle="0" />
</shape>

2. 在目标listview下方添加一个view,view的背景使用我们新建的 mygradient.xml,如果在listview和view的外围包裹有linearlayout,请将linearlayout的orientation设置为vertical!
<ListView android:id="@+id/lvProvider"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" />
<View android:id="@+id/divider"
      android:layout_width="fill_parent"
      android:layout_height="1dip"
      android:background="@drawable/mygradient" />

=====================================================================
=====================================================================
或者使用下段代码:
<View
    android:layout_width="fill_parent"
    android:layout_height="1px"
    android:background="?android:attr/listDivider"
/>

哈哈...第一种方案是当时为了实现效果,google后瞎折腾出来的,方案二则是在翻阅android source code时意外的发现,实在是很方便啊!

效果图如下:
  • 大小: 14.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics