Android 如何使用shape绘制只有一个圆角的矩形

来源:互联网 发布:手机电池寿命检测软件 编辑:程序博客网 时间:2024/06/01 08:40

      昨天UI设计师又给我出了一个难题敲打不过这难不倒我,哈哈

           挺好看的页面,看着也不是很难,但是,设计师阴险的跟我说最下面的按钮是只有一个圆角骂人

好吧,二话不说开始搭布局吧。上面的布局都很简单,下面的按钮倒是让我琢磨了一段时间。对于这种按钮大家第一反应就是用shape画个圆角矩形

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <solid android:color="@color/color_default" />    <corners android:radius="8dp" /></shape>

很简单的几行代码,但是还没有实现我们想要的效果,查阅资料知道corner属性不止radius,还有另外四个可以控制圆角大小的属性,分别是 topLeftRadius、topRightRadius、bottomLeftRadius、bottomRightRadius,特别要注意的是bottomLeftRadius是设置右下角半径的,这个不要弄混了。


<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <solid android:color="@color/color_default" />    <corners        android:topLeftRadius="0dp"        android:topRightRadius="0dp"        android:bottomLeftRadius="0dp"        android:bottomRightRadius="8dp" /></shape>

这次应该可以实现设计图了吧,可是模拟器上怎么都是有两个圆角,不是我们想要的效果,于是各种查阅资料,试了很多方法还是达不到想要的,最后实在没办法了,真机跑一下试试吧,卧槽,完美实现,早说就不瞎折腾那么久了大哭

所以说大家以后尽量用真机测试,避免出现类似情况。


      欢迎大家指教 :)

0 0
原创粉丝点击