Android实现button一边圆角一边直角
2016-03-30 14:25
459 查看
Android中要实现如下图的效果:
这个要在真机中才能看出效果!!
switch_button_left_checked.xml
view
sourceprint?
switch_button_left.xml
view
sourceprint?
switch_button_right_checked.xml
view
sourceprint?
switch_button_right.xml
view
sourceprint?
button.xml
view
sourceprint?
这个要在真机中才能看出效果!!
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
相关文章推荐
- Android Context简介
- Android Button 带点击效果的圆角
- android内存泄漏分析
- Android打补丁 热修复(HotFix)小结
- android LOG
- 对android 回调机制的总结
- android获取屏幕的高低
- Android中自定义属性的使用
- 使用Visual Studio 2015开发Android 程序
- Android 仿今日头条首页标题栏效果
- 判断访问浏览器客户端类型(pc,mac,ipad,iphone,android)
- Android项目中如何用好构建神器Gradle?
- Android Studio中实现图片倒影效果
- Cordova开发平台配置--Android
- Android 调节图片工具类
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.
- Android常用功能代码
- Android 工具
- android图片的压缩和水印
- Android性能优化之Bitmap的内存优化