绕过科特林景观的角落

时间:2020-04-20 20:38:09

标签: android android-studio kotlin

我在科特林(Kotlin)有这个 View

<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"
/>

,由于这是一个 Dot ,因此我需要四舍五入,并且我一直在研究和测试如何才能做到这一点,但是我找不到答案。

我该如何解决?

1 个答案:

答案 0 :(得分:0)

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

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"
/>