您的位置:首页 > 移动开发 > Android开发

Android实现button一边圆角一边直角

2016-03-30 14:25 459 查看
Android中要实现如下图的效果:



这个要在真机中才能看出效果!!

switch_button_left_checked.xml

view
sourceprint?

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>


switch_button_left.xml

view
sourceprint?

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

view
sourceprint?

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

view
sourceprint?

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

view
sourceprint?

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: