1.类似以下需求
2.实现步骤
第一步:就是在res/drawable中创建half_shape.xml(命名主要看个人)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 设置背景填充色 -->
<solid android:color="#5069ff" />
<!-- 设置边框宽度为1dp,边框颜色 -->
<stroke
android:width="1dp"
android:color="#F1F3FF" />
<!-- 设置按钮圆角半径为25dp -->
<corners android:bottomRightRadius="25dp"
android:topRightRadius="25dp"/>
</shape>
主要在于: corners 圆角的设置 属性 bottomRightRadius 右下角圆角 topRightRadius 右上角圆角,由此实现半边圆角的需求
第二步:在控件中引用这个half_shape.xml
<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:background="@drawable/login_code"
android:text="获取验证码"
android:textColor="#ffffff"
android:textSize="13sp" />
总结
这个是开发的时候的小技巧,其实很简单。这个按钮效果主要是当你需要的那边变成圆角就改变这里的代码就可以了。希望对Android开发的小伙伴有用。
android:topLeftRadius=""//上面左边的角度
android:topRightRadius=""//上面的右边的角度
android:bottomRightRadius=""//下面右边的角度
android:bottomLeftRadius=""//下面左边的角度