Android的 - 绘制一个圆角在顶部只 [英] Android - drawable with rounded corners at the top only

查看:715
本文介绍了Android的 - 绘制一个圆角在顶部只的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个可绘制有一个圆角矩形作为背景:

I had this drawable to have a rounded rectangle as a background:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white" />
    <stroke android:width="1dp" android:color="@color/light_gray" />
    <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />
    <corners android:radius="6dp" />
</shape>

这是工作的罚款,符合市场预期。

This is working fine, as expected.

现在,我想改变这只是一轮顶部边角,所以我就改成这样:

Now, I want to change this to only round the top corners, so I change it to this:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white" />
    <stroke android:width="1dp" android:color="@color/light_gray" />
    <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />
    <corners android:topLeftRadius="6dp" android:topRightRadius="6dp"
             android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
</shape>

但现在没有一个角落是圆的,我得到一个普通的矩形。我缺少的是在这里吗?

But now none of the corners are rounded and I get a plain rectangle. What am I missing here?

推荐答案

先给这些值:

 <corners android:topLeftRadius="6dp" android:topRightRadius="6dp"
         android:bottomLeftRadius="0.1dp" android:bottomRightRadius="0.1dp"/>

请注意,我已经改变了 0dp 0.1dp

Note that I have changed 0dp to 0.1dp.

编辑:见Alex的评论如下更清洁的版本

See Alex's comment below for a cleaner version

这篇关于Android的 - 绘制一个圆角在顶部只的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆