设置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布局中实现圆角边框的更多相关文章

  1. 【Android】Android布局中实现圆角边框

    设置corners_bg.xml 设置边框圆角可以在drawable-mdpi目录里定义一个xml: <?xml version="1.0" encoding="u ...

  2. Android开发(三)——Android布局中实现圆角边框

    设置corners_bg.xml(设置边框圆角可以在drawable-mdpi目录里定义一个xml): <?xml version="1.0" encoding=" ...

  3. Android布局中的空格以及占一个汉字宽度的空格的实现

    在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格:  窄空格:  一个汉字宽度的空格:   [用两个空格(  )占一个汉字的宽度时,两个空格比 ...

  4. Android布局中的空格以及占一个汉字宽度的空格,实现不同汉字字数对齐

    前言 在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格: (普通的英文半角空格但不换行) 窄空格:   (中文全角空格 (一个中文宽度))   ...

  5. android布局中使用include及需注意点

    在android布局中,使用include,将另一个xml文件引入,可作为布局的一部分,但在使用include时,需注意以下问题: 一.使用include引入 如现有标题栏布局block_header ...

  6. Android布局中涉及的一些属性

    Android:gravity属性 线性布局常见的就是利用LinearLayout进行布局,其中有个比较重要的属性就是android:gravity,在官方文档中是这么描述这个属性的:指定一个元素怎么 ...

  7. Android 布局中 如何使控件居中

    首先要分两种不同情况,在两种不同的布局方式下:LinearLayout 和RelativeLayout 1. LinearLayout a). android:layout_gravity=" ...

  8. 【转】在Android布局中使用include和merge标签

    内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...

  9. android 布局中 layout_gravity、gravity、orientation、layout_weight【转】

    线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...

随机推荐

  1. The PHP Package 之 monolog[转]

    Monolog 发送你的日志到文件.到sockets.到邮箱.到数据库或(和)者其他网路存储服务(云).Monolog可以做到同时保存到一个或多个存储介质(后面的栈冒泡处理). 安装   $ comp ...

  2. items2 配色

    cat ~/.bash_profile #enables colorin the terminal bash shell exportexport CLICOLOR=1 #sets up thecol ...

  3. 14,SFDC 管理员篇 - 外部数据集成

    1,Connect an External Data Source, 添加新的数据源,填写如下 2, 点击Validate and Sync 按钮 3,添加Orders和Orders Details ...

  4. CentOS6上无法启动NFS服务

    CentOS6上无法启动NFS服务 1.系统环境 物理机:Windows 7(32位)旗舰版 虚拟机:CentOS 6.5 2.问题描述 安装好nfs应用程序之后,打算启动nfs服务,却出现以下的报错 ...

  5. cx_Oracle 中文乱码问题解决

    设置NLS_LANG环境变量 import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'

  6. window SVN设置忽略文件列表

    进入checkout的项目文件夹. 执行 mvn install.生成 target文件夹. 如果这时候不想让target文件夹纳入版本控制.则进入子文件夹,在target文件夹上 右键执行 查看设置 ...

  7. htnl5中设置文本单行显示,超出部分打省略号,鼠标移到文本时alt出全部文本内容

    Html代码: 1.<span class="my-span" title="无数无数无数无数无数">机构</span> Css样式: ...

  8. Linux常用命令1

    jps(Java Virtual Machine Process Status Tool)是JDK 1.5提供的一个显示当前所有Java进程pid的命令. jps [ options ] [ host ...

  9. group_concat函数使用

    t1表 语句: select type,group_concat(name) from t1 group by type 结果

  10. ORACLE 实例及RAC

    ORACLE 实例及RAC 一.问题 (1)现象 部署一个sh脚本到生产oracle服务器上,该sh脚本负责读取外系统提供的txt文件,然后用sql loader入库,由oracle服务器的cront ...