【问题标题】: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"
/>