【问题标题】:Rounding the corners of a View in Kotlin [duplicate]在 Kotlin 中舍入视图的角落 [重复]
【发布时间】:2020-04-20 20:38:09
【问题描述】:

我在 Kotlin 中有这个视图

<View
android:id="@+id/DotView"
android:layout_width="6.5dp"
android:layout_height="6.5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/colorPrimary"
/>

我需要圆角,因为它是一个,我一直在调查和测试如何才能圆角,但我找不到答案。 p>

我该如何解决?

【问题讨论】:

    标签: android android-studio kotlin


    【解决方案1】:

    您必须创建一个可绘制的形状 xml 文件并将视图的背景属性设置为可绘制文件!

    res/drawable/circle.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
        <solid android:color="@color/colorPrimary" />
    </shape>
    

    res/drawable/rounded.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/colorPrimary"/>
        <corners android:radius="5dp" />
    </shape>
    

    并将背景设置为这样查看:

    <View
    android:id="@+id/DotView"
    android:layout_width="6.5dp"
    android:layout_height="6.5dp"
    android:layout_marginBottom="10dp"
    android:layout_gravity="bottom|center_horizontal"
    android:background="@drawable/rounded"
    />
    

    【讨论】:

    • 它对我有用,谢谢!
    猜你喜欢
    • 2012-04-04
    • 2020-12-18
    • 1970-01-01
    • 2012-12-17
    • 2021-05-15
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    相关资源
    最近更新 更多