画一条线既可以在java代码里实现,也可以在drawable中实现。
总体来说在java代码里划线是比较麻烦的,如果涉及到在屏幕中的位置时。
如果能在xml中把view的事搞定,就不要放在java代码里。这才符合mvc分离原则。
方法一:
在xml中划线分两步:
1.在drawable中创建textview_single_line.xml文件。代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:width="1dp"
android:color="#007aff"/>
<size android:height="2dp"/>
</shape>
2.在textview属性中引用。
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="54dp"
android:background="@drawable/tv_single_line"
/>
shape标签中子元素具体用法参见。
http://blog.csdn.net/bear_huangzhen/article/details/24488337
——————————————————————————————————————————–
2015.8.12 Edit
笔者才发现,原来还有一种方法在xml中划线,这种方法最简便。
方法二:
只需添加< View >标签,并设置其属性。
<!--竖线-->
<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#66CCFF"
android:layout_gravity="center_horizontal"
/>
<!--横线-->
<View
android:layout_height="1px"
android:layout_width="match_parent"
android:background="#66CCFF"
/>