您的位置:首页 > 其它

给TableLayou绘制边框--简单方法

2014-06-08 19:09 155 查看
最简单的方法是直接在每个TableRow前加上View控件,自动会加上一条线,如下:

<View

android:width="match_parent"

android:background="#af3489"

/>

但是似乎不合乎我们的想象,下面的方法是在res/drawable文件夹下建立xml文件,然后引用,每一个元素都会加上边框!很简单,但是不推荐,尤其是想绘制n*n的传统表格的时候!不过至少这个可以实现n*n的表格,也算说得过去!

步骤:

1.在res/drawable文件夹下建立table_frame_gray.xml文件

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="rectangle" >

<solid android:color="#ffffff" />

<stroke

android:width="0.01dp"

android:color="#848484" />

</shape>

引用时,,如下

<TableRow>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/table_frame_gray"
android:orientation="vertical" >

另外,当方框重合导致边线变粗时,参考如下这种方法,给指定边框加线,但是不推荐,因为到最后的时候,还是会出现边框不一样粗的情况!

android shape指定那几个边有边框

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
<item android:top="-1dp" android:right="-1dp" android:left="-1dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="#ffffff" />
</shape>
</item>

</layer-list>

http://stackoverflow.com/questions/2422120/open-sided-android-stroke
最好的办法,参考上一篇文章,个人意见。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: