给android图像设置圆角样式(Android Shapes – Example)(quoted)

来源:互联网 发布:淘宝权重查询 编辑:程序博客网 时间:2024/06/10 11:09

Android Shapes – Example

In Android you can use Shape Drawables to define background, borders and gradients for your Views. You find the possible types here.

To define a shape create a XML file in your drawable folder. For example:

?
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="rectangle">
     <stroke android:width="2dp" android:color="#FFFFFFFF" />
     <gradient android:startColor="#DD000000" android:endColor="#DD2ECCFA"
            android:angle="225"/>
 
    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
     android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
        

Assign it for example to a LinearLayout.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/myshape">
    <EditText android:layout_width="fill_parent" android:text="1"
        android:layout_height="wrap_content" android:id="@+id/editText1"
        android:inputType="numberSigned"
        android:layout_margin="5dip" android:gravity="center">
        <requestFocus></requestFocus>
    </EditText>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/button1"
        android:text="@string/start"></Button>
</LinearLayout>

And you get:

instead of

I hope this helps.