Android系统。圆形矩形

时间:2014-11-10 11:35:56

标签: android android-drawable rect

如何创建一个最大圆角的矩形?

enter image description here

我试过了:

<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">

    <size android:width="44dp"
        android:height="100dp"/>

    <solid android:color="#8c51ff"/>
    <corners android:radius="24dp"/>


</shape>

2 个答案:

答案 0 :(得分:5)

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

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

    <solid android:color="@color/pure_white_color" />  
    <corners android:radius="25dp"/>    
    <stroke
        android:width="1dip"
        android:color="@color/text_view_border_color" />
  </shape>

创建一个像“rounded.xml”的xml,并将按钮的背景设置为android:background="@drawable/rounded

答案 1 :(得分:1)

你可以像这样创建一个矩形:

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

<!-- view background color -->
<solid
    android:color="@color/white" >
</solid>

<!-- If you want to add some padding -->
<padding
    android:left="5dp"
    android:top="5dp"
    android:right="5dp"
    android:bottom="5dp"    >
</padding>

<!-- Here is the corner radius -->
 <corners
    android:radius="6dp">
</corners> 

</shape>

希望这能回答你的问题。