Android中shape的使用

PS:通常情况下,我们在写安卓程序的时候,会用到表格,比如说,需要一个上左右角是有弧度,下左右角没有弧度的一个弹出框,又或者是需要把一个图片用给一个表格框起来来等,这些功能shape都可以做到。但是这里面有坑,我之前用的androidstudio2.2,创建shape文件的时候默认是api23及以上的,所有属性都能正常使用,但是今天我换到studio1.5的时候,选的api是19,里面的圆角属性一直不能同时使用,换到22还是不行,我一直以为是版本问题,就把studio升级到了2.0作为测试一下,但还是不行,巧的是换到23就可以了,我不知道其他小伙伴是不是出现过这种情况,如果有的话,就照我这个方法试一下,如果没有,那就学一下shape属性的使用也是不错的哟。

如代码

<corners android:bottomLeftRadius="30dp"
        android:bottomRightRadius="0dp"
        android:topLeftRadius="30dp"
        android:topRightRadius="0dp"></corners>
API23之前效果一直是这样的



换到API23后就是这样的了:


切换API:


所以建议大家使用的时候多切换一下API,怕是API影响了效果,如果有什么问题,或者我说错了,大家可以给我留言,互相探讨一下

1:画边框

划表格框
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >

	//表格的边框
        <stroke
            android:width="1dp"
            android:color="#000000" />
//内部的颜色
        <gradient
            android:angle="225"
            android:endColor="#CCE8CF"
            android:startColor="#CCE8CF" />

</shape
对于边框stroke,可以控制边框的样式,比如说是dash破折号,破折号间隔13dp,宽度10dp.
<stroke android:color="@color/colorAccent" android:width="2dp"
    android:dashGap="13dp" android:dashWidth="10dp">

</stroke>

2:一头有弧度而另一头没有弧度

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
//角落
    <corners
       android:topLeftRadius="15dp"
        android:bottomLeftRadius="15dip"
        android:topRightRadius="0dip"
        android:bottomRightRadius="0dip"
        />
//里面填充的颜色
    <solid
        android:color="#666666"
        />
</shape>


3:里面是一张图片,外面是一个边框(类似于表格)
或者是两边有边线,中间是空的(白色或者透明),原理是叠层,下面的item把上面的item盖住了。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- This is the main color -->
    <item >
        <shape>
            <solid android:color="#000000" />

        </shape>
    </item>
    <!-- This is the line -->
    <item
        android:left="2dp"
        android:right="4dp"
        android:top="2dp"
        android:bottom="2dp"
        android:drawable="@drawable/a"
        >

    </item>
</layer-list>
       


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值