且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Android UI 中绘制圆角矩形?

更新时间:2023-01-05 14:55:46

在您的布局 xml 中执行以下操作:

In your layout xml do the following:

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

    <solid android:color="@android:color/holo_red_dark" />

    <corners android:radius="32dp" />

</shape>

通过改变 android:radius 你可以改变角的半径"数量.

By changing the android:radius you can change the amount of "radius" of the corners.

<solid> 用于定义drawable的颜色.

<solid> is used to define the color of the drawable.

您可以使用 android:bottomLeftRadiusandroid:bottomRightRadiusandroid:topLeftRadius 替换 android:radiusandroid:topRightRadius 来定义每个角的半径.

You can use replace android:radius with android:bottomLeftRadius, android:bottomRightRadius, android:topLeftRadius and android:topRightRadius to define radius for each corner.