简体   繁体   English

在顶部android drawable XML上带有笔触的圆角矩形

[英]Rounded rectangle with stroke on top android drawable XML

I was trying to make a drawable using XML in android. 我试图在Android中使用XML来绘制图片。 The requirement is I need to have a rounded rectangle(all 4 corners rounded) with a stroke of 7dp height only on the top edge. 要求是我需要有一个仅在顶部边缘具有7dp高度的笔触的圆角矩形(所有4个角都圆角)。 I am using the following XML for that: 我为此使用以下XML:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <stroke android:width="5dp" android:color="@color/theme_color" />
            <solid android:color="@color/theme_color" />
            <corners
                android:radius="7dp"/>
            <padding android:top="7dp"/>
        </shape>
    </item>

    <item>
        <shape
            android:shape="rectangle">
            <stroke android:width="1dp" android:color="@color/designer_cell_background" />
            <solid android:color="@color/designer_cell_background" />
            <corners
                android:radius="7dp"
                android:topRightRadius="0dp"
                android:topLeftRadius="0dp"/>
            <padding android:bottom="1dp"/>
        </shape>
    </item>
</layer-list>

I am getting this working almost OK, except that the bottomRight and bottomLeft corners are not rounded. 我的工作几乎可以了,除了不对bottomRight和bottomLeft角进行了圆角处理。

Question - 1 : How to get the bottom corners rounded? 问题-1:如何使下角变圆?

Question - 2 : Is this the correct way to achieve what I actually want? 问题-2:这是实现我实际想要的正确方法吗? Is there a better way? 有没有更好的办法? I am asking this because, I understand what I do here is actually making two rectangles, one on top of another, the second one is being slightly lowered from the top edge of the first rectangle so that the color of the first rectangle appears as a line on top of the second one. 我问这个问题是因为,我了解我在这里实际上是在制作两个矩形,一个在另一个矩形上,第二个矩形从第一个矩形的顶部边缘稍微放下,以便第一个矩形的颜色显示为在第二个的顶部。 And then adding corner radius to each rectangle individually. 然后分别向每个矩形添加角半径。 I don't think it is the right solution. 我认为这不是正确的解决方案。 But I failed when I tried to add a stroke of 7dp width to the top of a rounded rectangle. 但是,当我尝试将7dp宽度的笔触添加到圆角矩形的顶部时,我失败了。 The stroke I gave was appearing on all the edges. 我给的笔触出现在所有边缘上。

EDIT 编辑

Here is what I want: 这是我想要的:

预期产量

And this is what I currently get: 这就是我目前得到的:

实际产量

        <stroke
            android:width="1dp"
            android:color="#FFFFFF" />

        <solid android:color="#ffffff" />

        <padding
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />

        <corners android:radius="12dp" />

    </shape>

ur using the radius value increased curve shape wil increase ur使用半径值增加时曲线形状会增加

try this is works let me know 试试这个是让我知道的作品

this tool is helps me you can also get help from it 这个工具对我有帮助,您也可以从中获得帮助

http://angrytools.com/android/button/ http://angrytools.com/android/button/

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <stroke android:width="5dp" android:color="@color/theme_color" />
        <solid android:color="@color/theme_color" />
        <corners
            android:radius="7dp"/>
        <padding android:top="7dp"/>
    </shape>
</item>

<item>
    <shape
        android:shape="rectangle">
        <stroke android:width="1dp" android:color="@color/designer_cell_background" />
        <solid android:color="@color/designer_cell_background" />

       <corners
           android:topLeftRadius="0dp"
           android:topRightRadius="0dp"
           android:bottomLeftRadius="7dp"
           android:bottomRightRadius="7dp"/> 

        <padding android:bottom="1dp"/>
    </shape>
</item>

i think you should create 2 shapes the black one and the red one, just overlay the other shape to become the image you're looking for. 我认为您应该创建两种形状,黑色和红色两种,只需覆盖另一种形状即可成为您想要的图像。 you can't accomplish that with one shape in android. 您无法在android中使用一种形状来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM