android中<shape>圆角的bug

android的兼容性真是一个不可忽略的问题,今天测试时发现使用xml定义Shape drawable在android 2.1上存在bug

<?xml version="1.0" encoding="UTF-8"?>
<shape android:shape="rectangle"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#319ED0"/>

    <corners
        android:bottomLeftRadius="0.0dip"
        android:bottomRightRadius="8.0dip"
        android:topLeftRadius="8.0dip"
        android:topRightRadius="0.0dip" />

</shape>
把上面的xml定义作为Button的background时,在android 2.2和android 2.3都能正常显示圆角;但在android 2.1的真机和模拟器上均无法显示圆角

研读了一下android doc,发现这么一句话

Note: Every corner must (initially) be provided a corner radius greater than 1, or else no corners are rounded. If you want specific corners to not be rounded, a work-around is to use android:radius to set a default corner radius greater than 1, but then override each and every corner with the values you really want, providing zero ("0dp") where you don't want rounded corners.
于是改为
<?xml version="1.0" encoding="UTF-8"?>
<shape android:shape="rectangle"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#319ED0"/>

    <corners
        android:radius="1dip"
        android:bottomLeftRadius="0dip"
        android:bottomRightRadius="8.0dip"
        android:topLeftRadius="8.0dip"
        android:topRightRadius="0dip" />

</shape>
一切正常

google了一下,发现http://code.google.com/p/android/issues/detail?id=939,原来多年以前就有人提过这个bug了,高人给出了建议

<corners android:bottomRightRadius="0.1dp"
             android:bottomLeftRadius="7dip"
             android:topLeftRadius="7dip"
             android:topRightRadius="0.1dp"/>
使用很小的radius来到达一个近似与“方角”的效果,恩,很好的work around






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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值