如何在安卓系统中创建这种可绘制的形状?

3

我需要使用shape xml在Android中制作这个形状。

enter image description here

该形状需要呈矩形,但在左上角和右上角具有圆角,而底部角落保持不变。

我尝试了以下代码,但无效:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="rectangle" >
    <corners
    android:topLeftRadius="10dp"
    android:topRightRadius="10dp" 
      />
    <gradient
    android:angle="270"
    android:endColor="@color/Red"
    android:startColor="@color/Red"
    android:type="linear" />
    </shape>
2个回答

4
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

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

    <corners
       android:topLeftRadius="4dp"
        android:topRightRadius="4dp" />

    <padding
        android:bottom="5dip"
        android:left="10dip"
        android:right="10dip"
        android:top="5dip" />

</shape>

1

<corners>设置为像XML中那样

<corners 
   android:radius="1dp" 
   android:topLeftRadius="10dp" 
   android:topRightRadius="10dp" 
   android:bottomLeftRadius="0dp"    
   android:bottomRightRadius="0dp"/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接