Android使用 Shape 画边框线
1、布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF" android:orientation="vertical" > <!-- 表格布局 --> <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dip" > <!-- 表格布局:第一行 --> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_top_corner_no_bottom_line" android:padding="10dip" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="10dip" android:text="姓名:" > </TextView> <EditText android:id="@+id/bankingYourNameEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:background="@null" android:singleLine="true" > </EditText> </TableRow> <!-- 表格布局:第二行 --> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_no_corner_without_bottom" android:padding="10dip" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="10dip" android:text="联系电话:" > </TextView> <EditText android:id="@+id/bankingContactTelEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:background="@null" android:inputType="phone" android:singleLine="true" > </EditText> </TableRow> <!-- 表格布局:第三行 --> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_bottom_corner_no_top_line" android:padding="10dip" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="10dip" android:text="联系电话:" > </TextView> <EditText android:id="@+id/bankingContactTelEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:background="@null" android:inputType="phone" android:singleLine="true" > </EditText> </TableRow> </TableLayout> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Button" /> </LinearLayout>
2、表格布局中每个TableRow表示一行,TableRow中的每个基本控件都是一列,这是一个三行两列的布局
这里的表格背景是自定义的shape,下面分别看一下三个shape的代码。
shape_top_corner_no_bottom_line.xml文件:顶部带圆角 白色背景 灰色边框 无下边框 长方体
<?xml version="1.0" encoding="UTF-8"?> <!-- 顶部带圆角 白色背景 灰色边框 无下边框 长方体 --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <solid android:color="#FFFFFF" /> <corners android:topLeftRadius="10dp" android:topRightRadius="10dp" android:bottomRightRadius="0.1dp" android:bottomLeftRadius="0.1dp" /> <stroke android:width="1dp" android:color="#ffa8abad" /> </shape> </item> <item android:top="1dp" android:left="1dp" android:right="1dp"> <shape> <solid android:color="#FFFFFF" /> <corners android:topLeftRadius="10dp" android:topRightRadius="10dp" android:bottomRightRadius="0.1dp" android:bottomLeftRadius="0.1dp" /> <stroke android:width="1dp" android:color="#ffffffff" /> </shape> </item> </layer-list>
3、shape_no_corner_without_bottom.xml文件:不带圆角 白色背景 灰色边框 无下边框 长方体
<?xml version="1.0" encoding="UTF-8"?> <!-- 不带圆角 白色背景 灰色边框 无下边框 长方体 --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape> <solid android:color="#FFFFFF" /> <stroke android:width="1dp" android:color="#ffa8abad" /> </shape> </item> <item android:left="1dp" android:right="1dp" android:top="1dp"> <shape> <solid android:color="#FFFFFF" /> <stroke android:width="1dp" android:color="#ffffffff" /> </shape> </item> </layer-list>
4、shape_bottom_corner_no_top_line.xml文件:底部圆角 白色背景 灰色边框 长方体
<?xml version="1.0" encoding="UTF-8"?> <!-- 底部圆角 白色背景 灰色边框 长方体 --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <solid android:color="#FFFFFF" /> <corners android:topLeftRadius="0.1dp" android:topRightRadius="0.1dp" android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" /> <stroke android:width="1dp" android:color="#ffa8abad" /> </shape> </item> <item android:top="1dp" android:bottom="1dp" android:left="1dp" android:right="1dp"> <shape> <solid android:color="#FFFFFF" /> <corners android:topLeftRadius="0.1dp" android:topRightRadius="0.1dp" android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" /> <stroke android:width="1dp" android:color="#ffffffff" /> </shape> </item> </layer-list>
5、说明:
shape_top_corner_no_bottom_line.xml
shape_no_corner_without_bottom.xml
shape_bottom_corner_no_top_line.xml
以上三个文件都存放在 drawable 中。
6、效果图查看附件。
文章引自:http://www.linuxidc.com/Linux/2012-09/70661.htm
相关推荐
首先,在res下面新建一个文件夹drawable,在drawable下面新建三个xml文件:shape_corner_down.xml、shape_corner_up.xml和shape_corner.xml,分别是下面两个角是圆角边框,上面两个角是圆角边框,四个角全部是圆角...
shape实现控件圆角,背景,边框等属性
android-shape-imageview - 图片圆角、三角、五角、圆形、多角
主要介绍了android shape的使用及渐变色、分割线、边框、半透明阴影,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Android中使用Shape自定义形状
Android Studio 实现对话框圆角,毛玻璃模糊效果
android 代码实现shape GradientDrawable
圆形,圆角,带边框的圆形imageView,以及白色边框的圆形imageview
本文实例讲述了Android开发圆角Button按钮实现过程,分享给大家供大家参考,具体内容如下 需求及效果图: 实现思路: 1、shape实现圆角 在drawable新建两个xml 文件, 这两个 xml文件用shape 实现了圆角效果。 Note:...
android shape可以帮助我们实现很多的效果,比如:圆角、虚线边框、部分圆角、颜色的渐变等效果,同时源文件给出了android4.0系统下虚线会变成实线的解决办法。
本文实例讲述了Android编程实现圆角边框的方法。分享给大家供大家参考,具体如下: 设置边框圆角可以在drawable-mdpi目录里定义一个xml: <?xml version=1.0 encoding=utf-8?> <shape xmlns:android=...
主要给大家介绍了关于Android中利用shape实现各种简单的形状的相关资料,文中给出了详细的示例代码供大家参考学习,需要的朋友们下面跟着小编一起来学习学习吧。
首先我将贴出几种实现圆角边框的dmeo程序效果图: 方式一:使用shape元素填充背景,设置圆角/带弧度的角 1、首先在 \res\drawable下新建Shape为根元素的资源文件:corners_bg.xml, 代码如下: <?xml version=...
通过 shape 实现梯形(可以用于右下角角标等) 通过 shape 实现梯形(可以用于左下角角标等) 通过 shape 实现正三角形(可以用于气泡上的三角等) 作者:xueand
android 用shape画出来的颜色做背景时,动态的改变它的颜色属性。
android中shape的使用: http://blog.csdn.net/luohai859/article/details/41038443
Android-shape标签的使用,让我们的界面更加高大上档次
最近要实现个圆角边框的对话框设计图,查了网上很多种实现,都差不多,从中得到灵感,实现了另一种方式,利用layer-list: 先来看看实现的效果如下: 首先在drawable目录下定义好圆角背景文件dialog_corner_bg.xml ...
利用shape优化android UI
Android创建抗锯齿透明背景圆角图像