Android-如何给View添加边框,边框颜色和线的粗细可以自定义
来源:互联网 发布:matlab矩阵一行写不下 编辑:程序博客网 时间:2024/05/19 16:49
一、使用场景
有时在开发中,遇到向表格形式的布局,这时该怎么办?
如果只是简单的一条横线或者竖线,直接使用TextView控件,宽或者高固定1dp或者2dp,高或者宽match parent,在定义一个background="#FF0000",这样就实现了单一的线条功能。线条的颜色就是指定的背景颜色,线粗就是宽或者高。
但是如果四条边框都有线,总不能一条一条的去拼接吧,这多费事。解决方法有2中,第一种方法是使用一张有背景线条的9-patch图片;方法二,自己制作一个shape布局,在需要使用的地方通过background属性引用即可。
下面就介绍第2种方法:
二、关键代码
1.shape_textview_cart.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <stroke android:width="1dp" android:color="#ebebeb" /> <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" /> <solid android:color="#00000000" /></shape>
2.引用的布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="120dp" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:background="@drawable/shape_textview_cart" android:orientation="horizontal" > <ImageView android:id="@+id/cart_image" android:layout_width="120dp" android:layout_height="120dp" android:layout_marginRight="1dp" android:src="@drawable/qzone" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <include layout="@layout/include_cart_listview_item_right_01" /> <include layout="@layout/include_cart_price_number" /> </LinearLayout></LinearLayout>3.效果图
0 0
- Android-如何给View添加边框,边框颜色和线的粗细可以自定义
- Android-如何给View添加边框,边框颜色
- 如何定义表格的边框线粗细及颜色
- xib 给View 添加边框 及 设置边框颜色
- 视图边框颜色和粗细,圆角
- Android:给View添加一个边框
- 给View添加阴影和边框
- 给指定的view添加边框
- android View如何画某条边的边框线
- iOS开发 给View添加指定位置的边框线
- 给Div添加边框颜色
- 如何给布局套上带颜色的边框
- 给view添加虚线边框
- View的边框大小和颜色
- android给View设置边框 填充颜色 弧度
- Android给控件自定义边框和阴影
- Android自定义边框背景颜色的Toast
- Android给View画边框
- 关于博客
- overtimeRecording
- MATLAB GUI新手备忘录
- 有向图的强连通分量(最小生成树)
- Android开发系列(六):Android应用中文件的操作模式
- Android-如何给View添加边框,边框颜色和线的粗细可以自定义
- Leetcode: 3Sum Closest
- ZigZag Conversion leetcode
- android自定义弹出框样式实现
- hdu4751(判断二分图)
- hdu1561树形dp
- 如何选择开源协议
- How to make Closed polygon
- android笔记总结