本文主要是介绍Android 实现一边圆角一边直角的Button等View,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考:http://blog.csdn.net/luco2008/article/details/51014161
Android中要实现如下图的效果:
这个要在真机中才能看出效果!!
switch_button_left_checked.xml
01.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
02.
<shape xmlns:android=
"http://schemas.android.com/apk/res/android"
03.
android:shape=
"rectangle"
>
04.
05.
<!-- 填充的颜色:这里设置背景透明 -->
06.
<solid android:color=
"#ff304a"
/>
07.
<!-- 边框的颜色 :不能和窗口背景色一样 -->
08.
<stroke
09.
android:width=
"2dp"
10.
android:color=
"#ff304a"
/>
11.
<!-- 设置按钮的四个角为弧形 -->
12.
<!-- android:radius 弧形的半径 -->
13.
<corners
14.
android:bottomLeftRadius=
"5dip"
15.
android:bottomRightRadius=
"0dip"
16.
android:topLeftRadius=
"5dip"
17.
android:topRightRadius=
"0dip"
/>
18.
19.
<!-- padding:Button里面的文字与Button边界的间隔 -->
20.
<padding
21.
android:bottom=
"5dp"
22.
android:left=
"5dp"
23.
android:right=
"5dp"
24.
android:top=
"5dp"
/>
25.
26.
</shape>
01.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
02.
<shape xmlns:android=
"http://schemas.android.com/apk/res/android"
03.
android:shape=
"rectangle"
>
04.
05.
<!-- 填充的颜色:这里设置背景透明 -->
06.
<solid android:color=
"#00000000"
/>
07.
<!-- 边框的颜色 :不能和窗口背景色一样 -->
08.
<stroke
09.
android:width=
"2dp"
10.
android:color=
"#ff304a"
/>
11.
<!-- 设置按钮的四个角为弧形 -->
12.
<!-- android:radius 弧形的半径 -->
13.
<corners
14.
android:bottomLeftRadius=
"5dip"
15.
android:bottomRightRadius=
"0dip"
16.
android:topLeftRadius=
"5dip"
17.
android:topRightRadius=
"0dip"
/>
18.
19.
<!-- padding:Button里面的文字与Button边界的间隔 -->
20.
<padding
21.
android:bottom=
"5dp"
22.
android:left=
"5dp"
23.
android:right=
"5dp"
24.
android:top=
"5dp"
/>
25.
26.
</shape>
switch_button_right_checked.xml
01.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
02.
<shape xmlns:android=
"http://schemas.android.com/apk/res/android"
03.
android:shape=
"rectangle"
>
04.
05.
<!-- 填充的颜色:这里设置背景透明 -->
06.
<solid android:color=
"#ff304a"
/>
07.
<!-- 边框的颜色 :不能和窗口背景色一样 -->
08.
<stroke
09.
android:width=
"2dp"
10.
android:color=
"#ff304a"
/>
11.
<!-- 设置按钮的四个角为弧形 -->
12.
<!-- android:radius 弧形的半径 -->
13.
<corners
14.
android:bottomLeftRadius=
"0dip"
15.
android:bottomRightRadius=
"5dip"
16.
android:topLeftRadius=
"0dip"
17.
android:topRightRadius=
"5dip"
/>
18.
19.
<!-- padding:Button里面的文字与Button边界的间隔 -->
20.
<padding
21.
android:bottom=
"5dp"
22.
android:left=
"5dp"
23.
android:right=
"5dp"
24.
android:top=
"5dp"
/>
25.
26.
</shape>
switch_button_right.xml
01.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
02.
<shape xmlns:android=
"http://schemas.android.com/apk/res/android"
03.
android:shape=
"rectangle"
>
04.
05.
<!-- 填充的颜色:这里设置背景透明 -->
06.
<solid android:color=
"#00000000"
/>
07.
<!-- 边框的颜色 :不能和窗口背景色一样 -->
08.
<stroke
09.
android:width=
"2dp"
10.
android:color=
"#ff304a"
/>
11.
<!-- 设置按钮的四个角为弧形 -->
12.
<!-- android:radius 弧形的半径 -->
13.
<corners
14.
android:bottomLeftRadius=
"0dip"
15.
android:bottomRightRadius=
"5dip"
16.
android:topLeftRadius=
"0dip"
17.
android:topRightRadius=
"5dip"
/>
18.
19.
<!-- padding:Button里面的文字与Button边界的间隔 -->
20.
<padding
21.
android:bottom=
"5dp"
22.
android:left=
"5dp"
23.
android:right=
"5dp"
24.
android:top=
"5dp"
/>
25.
26.
</shape>
button.xml
01.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
02.
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
03.
android:layout_width=
"match_parent"
04.
android:layout_height=
"match_parent"
05.
android:orientation=
"horizontal"
06.
android:padding=
"10dp"
>
07.
08.
<Button
09.
android:id=
"@+id/wangdaileiBtn"
10.
android:layout_width=
"0dp"
11.
android:layout_height=
"40dp"
12.
android:layout_weight=
"1"
13.
android:scaleType=
"fitXY"
14.
android:text=
""
15.
android:background=
"@drawable/switch_button_left_checked"
/>
16.
17.
<Button
18.
android:id=
"@+id/baobaoleiBtn"
19.
android:layout_width=
"0dp"
20.
android:layout_height=
"40dp"
21.
android:layout_weight=
"1"
22.
android:text=
""
23.
android:scaleType=
"fitXY"
24.
android:background=
"@drawable/switch_button_right"
/>
25.
26.
</LinearLayout>
转载自:http://www.it165.net/pro/html/201503/36211.html 这篇关于Android 实现一边圆角一边直角的Button等View的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!