以前一直遇到各种button圆角的需求,然后不会 只能找美工切图,然后在android:background="" 然后吧背景图放进去,取巧的办法。
找了个时间看了看button的圆角做法,记录下;
在drawble文件夹创建一个xml文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<!-- 背景色-->
<solid android:color="#ff00ffff"/>
<!-- 圆角-->
<corners android:radius="30dp"/>
<!--设置边框线的宽度和颜色-->
<stroke android:width="3dp" android:color="@color/colorPrimaryDark"/>
<padding
android:bottom="15dp"
android:left="15dp"
android:right="20dp"
android:top="10dp"
/>
<!-- 在这里写的代码,是指那种特殊要求,圆角下面的那句代码可以注释掉,如果用这种-->
<corners android:topRightRadius="40dp"
android:topLeftRadius="100dp"
android:bottomLeftRadius="40dp"
android:bottomRightRadius="30dp"/>
</shape>
每个都有注释 。
<corners android:topRightRadius="40dp" //这句话的意思是右上角的圆角
android:topLeftRadius="100dp" //左上角的圆角
android:bottomLeftRadius="40dp" //左下角的圆角
android:bottomRightRadius="30dp"/> //右下角的圆角
每个圆角都可以单独使用。当然 看需求做吧
<padding
android:bottom="15dp" //向下15dp
android:left="15dp" //左15dp
android:right="20dp"
android:top="10dp"
/>
这个 可以自己调下dp大小就知道是做什么的了
android:drawableTop
android:drawableBottom
android:drawableLeft
android:drawableRight 这四个值表示引入图片,且该图片与文字排列的规则
引用一篇文章,这个文章详细的有写Android中shape的使用