shape文件圆角bug的一种解决方法
2014-12-01 21:59
204 查看
好吧,这可以说不是原创,只是总结而已。
最近项目中遇到一个问题,需要作出如下布局效果
这是两个按钮,按下时有颜色变化,本想用点九图片,但发现也不是很好布局,于是改用shape文件,其实此类扁平化的按钮效果,基本上都可以使用shape。
实现思路:
1.搞一个LinearLayout,水平的,给它设置android:background="@drawable/shapebg",其shapebg.xml 文件如下
2.两边分别弄两个button(我这用textview代替),中间放一根竖线,具体代码如下:
3.两边的textview分别设置圆角即实现如下效果
代码文件为:
经测试在android 3.0以下版本中,android:bottomLeftRadius,android:bottomRightRadius互换了,变成了对角的效果,如图
于是查找资料得知,此乃低版本bug,3.0以上版本已修复。但如何兼容呢,据说可以创建一个drawable-v14文件夹,此文件系统运行时高版本优先引用,正确的代码可以放到此文件夹中,其错误的文件即android:bottomLeftRadius,android:bottomRightRadius互换的文件可以放到正常的文件夹中。这种方法我没有试过,不知可不可行,然而这样总觉怪异。再次百度,发现可以使用layer-list绘制两层shape,叠加得到以上效果,这样可以避免左右下角互换的问题,代码如下
最近项目中遇到一个问题,需要作出如下布局效果
这是两个按钮,按下时有颜色变化,本想用点九图片,但发现也不是很好布局,于是改用shape文件,其实此类扁平化的按钮效果,基本上都可以使用shape。
实现思路:
1.搞一个LinearLayout,水平的,给它设置android:background="@drawable/shapebg",其shapebg.xml 文件如下
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#ffffff" /> <corners android:radius="15dip" /> <stroke android:width="1dip" android:color="#000000" /> </shape>
2.两边分别弄两个button(我这用textview代替),中间放一根竖线,具体代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <LinearLayout android:id="@+id/linear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="50dip" android:layout_marginLeft="50dip" android:background="@drawable/shapebg" android:padding="1dip" > <TextView android:id="@+id/textView1" android:layout_width="80dip" android:layout_height="50dip" android:background="@drawable/shapeleftlist" android:gravity="center" android:text="同意" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:background="#000000" /> <TextView android:layout_width="80dip" android:layout_height="50dip" android:background="@drawable/shaperightlist" android:gravity="center" android:text="拒绝" /> </LinearLayout> </RelativeLayout>
3.两边的textview分别设置圆角即实现如下效果
代码文件为:
<TextView android:id="@+id/textView2" android:layout_width="70dip" android:layout_height="40dip" android:layout_marginLeft="44dp" android:layout_marginTop="39dp" android:gravity="center" android:textColor="#ffffff" android:background="@drawable/yj" android:text="TextView" />shape文件为
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:topLeftRadius="10dip" android:topRightRadius="0dip" android:bottomLeftRadius="10dip" android:bottomRightRadius="0dip" /> <solid android:color="#456745" /> </shape>
经测试在android 3.0以下版本中,android:bottomLeftRadius,android:bottomRightRadius互换了,变成了对角的效果,如图
于是查找资料得知,此乃低版本bug,3.0以上版本已修复。但如何兼容呢,据说可以创建一个drawable-v14文件夹,此文件系统运行时高版本优先引用,正确的代码可以放到此文件夹中,其错误的文件即android:bottomLeftRadius,android:bottomRightRadius互换的文件可以放到正常的文件夹中。这种方法我没有试过,不知可不可行,然而这样总觉怪异。再次百度,发现可以使用layer-list绘制两层shape,叠加得到以上效果,这样可以避免左右下角互换的问题,代码如下
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <corners android:radius="15dip" /> <solid android:color="#00000000"/> </shape> </item> <item android:left="15dip"> <shape android:shape="rectangle" > <solid android:color="#00000000"/> </shape> </item> </layer-list>其原理是,先绘制一层全圆角的矩形,再在其上层覆盖一层无圆角矩形,偏移一定距离,遮盖掉右边的圆角,如此高低版本表现就一致了。
相关文章推荐
- chm文件打开提示mk@MSITStore***一种解决方法
- Bug:error LNK2019: unresolved external symbol的一种解决方法
- 一个NFS缓存管理包的bug导致文件系统满的问题和解决方法
- office2013 Word 在试图打开文件时遇到错误一种解决方法
- Spring Batch读取csv文件失败的一种解决方法
- ie引用js文件出现中文乱码的一种解决方法
- mysql导入sql文件出错的一种解决方法
- XML 文件中出现 & ? ? 这类特殊字符的一种解决方法
- eclipse中的android布局文件的快捷键Alt+/不起作用的一种解决方法
- log4cpp的RollingFileAppender异常情况下日志文件不拆分的一种可能解决方法
- 解决Eclipse项目中有sql-map-config.xml文件但是运行Junit测试ibatis时提示找不到该文件的一种方法
- 左侧图片 右侧块的实现方法---解决3像素bug的一种解决方案,不用浮动用绝对定位和margin-left
- .lnk文件 和一种较新的.lnk病毒及解决方法
- 解决ios6系统输入法bug的一种方法
- 打开了一个size不为零的文件,读取到的值却为零的一种分析和解决方法
- Mysql单文件存储删除数据文件容量不会减少的bug与解决方法
- 解决无耻迅雷在后台偷偷上传文件的一种方法
- Linux下生成core文件的临时解决方法-RHEL5.X bug
- mysql导入sql文件出错的一种解决方法
- “不能打开文件mk:@*.chm”怎么办?——提供一种windows7上打不开chm的解决方法