Android布局中实现圆角边框
设置corners_bg.xml
设置边框圆角可以在drawable-mdpi目录里定义一个xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
解释:
solid的表示填充颜色,为了简单,这里用的是白色。
而corners则是表示圆角,注意的是这里bottomRightRadius是左下角而不是右下角,bottomLeftRadius右下角。
上面的效果也可以像下面一样设置,如下:
<corners android:radius="5dp" />
引用corners_bg.xml
如果想引用这个xml,只需要@drawable/corners_bg.xml即可:
android:background="@drawable/corners_bg"
应用范例
<?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="match_parent"
android:background="#E1E0DE"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#2B3439"
android:gravity="center"
android:text="发现"
android:textColor="#FFFFFF"
android:textSize="20sp" /> <LinearLayout
android:id="@+id/login_div"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_margin="10dp"
android:background="@drawable/corners_bg"
android:gravity="center_vertical"
android:padding="10dp" > <ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/find_more_friend_photograph_icon" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="朋友圈"
android:textColor="#000"
android:textSize="18sp" />
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="101dp"
android:layout_margin="10dp"
android:background="@drawable/corners_bg"
android:orientation="vertical"
android:padding="10dp" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/find_more_friend_scan" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="扫一扫"
android:textColor="#000"
android:textSize="18sp" />
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_centerVertical="true" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/come_from_shake" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="摇一摇"
android:textColor="#000"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="101dp"
android:layout_margin="10dp"
android:background="@drawable/corners_bg"
android:orientation="vertical"
android:padding="10dp" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/find_more_friend_near_icon" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="附近的人"
android:textColor="#000"
android:textSize="18sp" />
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_centerVertical="true" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/come_from_bottle" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="漂流瓶"
android:textColor="#000"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout> <LinearLayout
android:id="@+id/login_div"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_margin="10dp"
android:background="@drawable/corners_bg"
android:gravity="center_vertical"
android:padding="10dp" > <ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/more_game" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="游戏中心"
android:textColor="#000"
android:textSize="18sp" />
</LinearLayout> </LinearLayout>
效果图
Android布局中实现圆角边框的更多相关文章
- 【Android】Android布局中实现圆角边框
设置corners_bg.xml 设置边框圆角可以在drawable-mdpi目录里定义一个xml: <?xml version="1.0" encoding="u ...
- Android开发(三)——Android布局中实现圆角边框
设置corners_bg.xml(设置边框圆角可以在drawable-mdpi目录里定义一个xml): <?xml version="1.0" encoding=" ...
- Android布局中的空格以及占一个汉字宽度的空格的实现
在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格: 窄空格: 一个汉字宽度的空格: [用两个空格( )占一个汉字的宽度时,两个空格比 ...
- Android布局中的空格以及占一个汉字宽度的空格,实现不同汉字字数对齐
前言 在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格: (普通的英文半角空格但不换行) 窄空格: (中文全角空格 (一个中文宽度)) ...
- android布局中使用include及需注意点
在android布局中,使用include,将另一个xml文件引入,可作为布局的一部分,但在使用include时,需注意以下问题: 一.使用include引入 如现有标题栏布局block_header ...
- Android布局中涉及的一些属性
Android:gravity属性 线性布局常见的就是利用LinearLayout进行布局,其中有个比较重要的属性就是android:gravity,在官方文档中是这么描述这个属性的:指定一个元素怎么 ...
- Android 布局中 如何使控件居中
首先要分两种不同情况,在两种不同的布局方式下:LinearLayout 和RelativeLayout 1. LinearLayout a). android:layout_gravity=" ...
- 【转】在Android布局中使用include和merge标签
内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...
- android 布局中 layout_gravity、gravity、orientation、layout_weight【转】
线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...
随机推荐
- onethink上传图片(资源)和预览
直接上干货 不废话了 普通上传: onthink框架 后台已经有图片和文件上传功能 controller里只需: public function addPicture(){ /* 调用文件上传组件上 ...
- Aptana插件安装方法
本人用的是Zend Studio10.0,在开发项目过程中,发现该软件无法对css和js进行代码提示,这样用起来很不方便,然后在网上找了一下Aptana插件 进入Aptana官网:http://www ...
- C++对象模型详解
原文链接:吴秦大神的C++对象模型. 何为C++对象模型? C++对象模型可以概括为以下2部分: 1.语言中直接支持面向对象程序设计的部分: 2.对于各种支持的底层实现机制. 语言中直接支持面向对象程 ...
- Hibernate框架简单应用
Hibernate框架简单应用 Hibernate的核心组件在基于MVC设计模式的JAVA WEB应用中,Hibernate可以作为模型层/数据访问层.它通过配置文件(hibernate.proper ...
- sql2000添加表注释,列注释 及修改 删除 注释
--创建表--create table 表(a1 varchar(10),a2 char(2)) --为表添加描述信息EXECUTE sp_addextendedproperty 'MS_Descri ...
- 转换,2D,3D
一,转换定义: 1,能够改变元素的形状,尺寸,位置 2,转换分两种: 2D转换:只能在X,Y轴发生改变: 例子:旋转(rotate).拉伸(scale).平移(move).倾斜(skew) 3D转换: ...
- RPC hessian简单案例
RPC(Remote procedure call) 远程服务调用. dubbox就是RPC框架,hessian是简单的RPC实现. 首先需要有接口及其实现类: 接口. public interfac ...
- DNS服务器原理
19.1 什么是DNS 主机名自动解析为 IP 就很重要!那就是 DNS. 19.1.1 用网络主机名取得IP的历史渊源 单一档案处理上网的年代: /etc/hosts 利用某些特定的 ...
- H5 JS API 02
1.1 网络状态 我们可以通过window. navigator.onLine来检测,用户当前的网络状况,返回一个布尔值,这个不能实时的通知. addEventListener 进行绑定online从 ...
- 解锁scott用户及设置密码
关于Oracle 10g scott用户解锁的方法两则 解决方法一. 首先确认已经安装oracle 数据库和客户端 在客户端DOS下执行如下语句: 注意提示符号 c:\sqlplus /nolog s ...