Android编程实现圆角边框布局效果的方法
作者:陶伟基Wiki 时间:2021-06-07 08:54:01
本文实例讲述了Android编程实现圆角边框布局效果的方法。分享给大家供大家参考,具体如下:
这里用的是TableLayout布局的。先看效果图
下面看下布局文件
<?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>
表格布局中每个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>
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>
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>
希望本文所述对大家Android程序设计有所帮助。
标签:Android,布局
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#中通过Command模式实现Redo/Undo方案
2021-07-12 14:58:59
轻松学习C#的属性
2022-07-21 06:24:04
![](https://img.aspxhome.com/file/2023/5/110175_0s.png)
基于c#用Socket做一个局域网聊天工具
2023-08-17 09:36:14
![](https://img.aspxhome.com/file/2023/6/119466_0s.png)
android 实现控件左右或上下抖动教程
2023-03-19 17:02:07
深入理解Android热修复技术原理之so库热修复技术
2023-11-19 15:02:10
![](https://img.aspxhome.com/file/2023/8/137178_0s.jpg)
c# 剔除sql语句'尾巴'的五种方法
2022-09-20 16:32:39
![](https://img.aspxhome.com/file/2023/8/125998_0s.png)
c#定时运行程序分享(定时程序)
2023-12-11 20:47:31
Spring Boot+Drools规则引擎整合详解
2023-11-28 20:33:00
JVM中的flag设置详解
2022-08-11 01:37:20
![](https://img.aspxhome.com/file/2023/7/108207_0s.jpg)
Android自定义实现图片加文字功能
2022-08-03 22:05:49
![](https://img.aspxhome.com/file/2023/6/88726_0s.png)
C#微信开发之启用开发者模式
2022-07-07 11:24:54
![](https://img.aspxhome.com/file/2023/9/91369_0s.png)
Mybatis一对多查询的两种姿势(值得收藏)
2023-07-01 00:20:08
![](https://img.aspxhome.com/file/2023/9/61669_0s.png)
android studio实现简单的计算器小功能
2022-07-22 17:53:26
![](https://img.aspxhome.com/file/2023/9/98619_0s.jpg)
android SDk中常用的java包介绍
2021-12-18 01:04:45
springboot自动配置原理以及spring.factories文件的作用详解
2021-12-20 20:19:27
![](https://img.aspxhome.com/file/2023/6/89586_0s.png)
Java基础之简单的图片处理
2022-08-12 03:49:01
![](https://img.aspxhome.com/file/2023/5/106185_0s.png)
C#实现BBcode转为Markdown的方法
2021-10-11 12:34:12
MyBatis查询结果resultType返回值类型的说明
2021-10-25 21:37:39
![](https://img.aspxhome.com/file/2023/9/79169_0s.jpg)
Android动态修改应用图标与名称的方法实例
2021-11-21 13:24:44
![](https://img.aspxhome.com/file/2023/0/125360_0s.jpg)
SpringBoot yaml中的数组类型取值方式
2022-10-14 20:05:36