Android:如何创建椭圆形尺寸的可绘制资源?

4
我正在尝试创建可绘制的资源椭圆形状或矩形形状,我想要的是确切的下面这种形状: enter image description here 但我得到了如下形状: enter image description here 我使用的是:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="rectangle" >

  <gradient
    android:startColor="#36D53D"
    android:centerColor="#36D53D"
    android:endColor="#36D53D"
    android:angle="90"/>
  <padding android:left="3dp"
    android:top="5dp"
    android:right="5dp"
    android:bottom="5dp" />

  <corners android:radius="160dp"></corners>
</shape>

如何创建我想要的形状?提前致谢。

1
创建一个可绘制的形状,它是一个矩形。使其实心并提供颜色,提供相应的宽度和高度大小,最后提供一个控制每个角半径的角落。尝试查看我的答案,希望能帮到你 :) - Ariel Magbanua
你不能在XML中完成它。 - pskink
3个回答

4
尝试使用这个椭圆形的代码。
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >

    <!-- fill/color -->
    <solid
        android:color="#ff0000"/>

    <!-- Control the width and height of the shape -->
    <size
        android:width="120dp"
        android:height="70dp"/>
</shape>

带圆角的矩形

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

    <!-- fill/color -->
    <solid
        android:color="#ff0000"/>

    <!-- Control the width and height of the shape -->
    <size
        android:width="200dp"
        android:height="70dp"/>

    <!-- Control the radius of each corners -->
    <corners
        android:topLeftRadius="30dp"
        android:topRightRadius="15dp"
        android:bottomLeftRadius="15dp"
        android:bottomRightRadius="15dp"/>
</shape>

3
试试这个:
<?xml version="1.0" encoding="utf-8"?>

  <shape xmlns:android="http://schemas.android.com/apk/res/android">
      <solid android:color="#189B5F" />
      <corners
          android:topLeftRadius="15dp"
          android:topRightRadius="15dp"
          android:bottomLeftRadius="15dp"
          android:bottomRightRadius="15dp"
          />
  </shape>

1
使用形状可绘制对象,对于android:shape属性设置为rectangle。
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
</shape>

增加角落的dp值可以保持检查。我认为给所有角落大约20-25dp的值将会给你那个形状。而且,纠正一下,它不是椭圆形,而是圆角矩形。

不行。如果我使用shape=oval,我会得到完整的椭圆大小。 - Aristo Michael
请检查修改后的答案。 - Rajen Raiyarela

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