Android圆角边框设计


      在AndroidUI设计中,大多数时候需要自定义组件圆角,如下:


当然,这也可以让UI设计师直接切图,作为背景使用。为了低耦合,这类简单的圆角设计,还是用代码比较方便。

首先在drawable文件下创建corner_edit.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    >

    <solid android:color="#ffff"/>
    <corners
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"
        android:bottomRightRadius="10dp"
        android:bottomLeftRadius="10dp"/>
    <stroke
        android:width="1dp"
        android:color="#000"/>
    </shape>
solid的color属性用来指明矩形内填充的颜色,corner的属性分别代表左右上下四个圆角半径,在这里,四个角圆角半径一样可以使用radius属性,同样能达到圆角的效果。stroke用来描边的属性,上图的width是1dp,下图是10dp,color就是边的颜色。

shape标签,除了有矩形的圆角,还可以制作其他图形,它共有四个值:


line代表的是直线,oval代表的是椭圆,ring代表的是环形,默认的是rectangle矩形。

然后在activity_main.xml文件使用它:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="圆角设计"
        android:background="@drawable/corner_edit"/>
    <LinearLayout
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"
        android:background="@drawable/corner"
        android:layout_width="100dp"
        android:layout_height="40dp">
        <TextView
            android:gravity="center"
            android:layout_gravity="center"
            android:layout_marginLeft="15dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="圆角设计"/>
    </LinearLayout>
    <EditText
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"
        android:gravity="center"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:background="@drawable/corner_edit"
        android:text="圆角设计"/>

</LinearLayout>

至此,普通的圆角设计就完成了,标签和属性不多,也不复杂,简单方便。

Demo下载

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值