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>
switch_button_left.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="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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值