Android學習之 實現圓角Button

2021-09-23 18:58:33 字數 1051 閱讀 3019

在drawable資料夾下新建btn_shape.xml檔案:

1

<?xml version="1.0" encoding="utf-8"?>

23 android:shape="rectangle">45

6 android:topleftradius="8dip"

7 android:toprightradius="8dip

8 android:bottomleftradius="8dip"

9 android:bottomrightradius="8dip"/>

10

先解釋一下上面的**:

1.shape用於定義形狀,有四種形狀(矩形rectangle| 橢圓oval | 直線line | 圓形ring)。

2.solid用於設定填充形狀的顏色。

3.corners用於建立圓角(只用於形狀是矩形)。

topleftradius、toprightradius、bottomleftradius、bottomrightradius分別設定左上,右上,左下,右下圓角的半徑。

使用方法:

android:background="@drawable/btn_shape"

1

2 android:layout_width="wrap_content"

3 android:layout_height="wrap_content"

4 android:id="@+id/button"

5 android:background="@drawable/btn_shape"

6 />

效果圖:

1

參考**:

Android學習之 實現圓角Button

在drawable資料夾下新建btn shape.xml檔案 1 23 android shape rectangle 45 6 android topleftradius 8dip 7 android toprightradius 8dip 8 android bottomleftradius 8...

Android學習之 實現圓角Button

在drawable資料夾下新建btn shape.xml檔案 1 23 android shape rectangle 45 6 android topleftradius 8dip 7 android toprightradius 8dip 8 android bottomleftradius 8...

android實現邊框圓角

1.在drawable 下新建 shape.xml 檔案 xml android radius為角的弧度,值越大角越圓。我們還可以把四個角設定成不同的角度,方法為 2.1設定成0dp無效,2.1以上版本可以,如果無效的話那就只能設成1dp了。2.設定引用 android background dra...