gpt4 book ai didi

android - 如何根据 Android Kotlin 中的宽度将圆角应用于 View

转载 作者:数据小太阳 更新时间:2023-10-29 02:33:03 26 4
gpt4 key购买 nike

我正在制作自定义进度条,如下图所示:

enter image description here

enter image description here

enter image description here

基本上,我创建了一个可绘制的 xml 背景文件:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="@color/jungleGreen"/>
<corners
android:bottomLeftRadius="40dp"
android:topLeftRadius="40dp"/>
</shape>

然后我将它应用到我正在使用的 View 中:

<View
android:id="@+id/progress_bar_placeholder_view"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginEnd="45dp"
android:background="@drawable/background_filled_patronage_progressbar"
app:layout_constraintTop_toTopOf="parent"/>

完全没问题,我可以实现方案 1 和方案 2,但是当条形图接近尾端时,我如何以编程方式设置 View 右上角和右下角的圆角,直到它看起来就像照片 3 一样?

谢谢。

最佳答案

试试这个

    public static void customView(View v, int backgroundColor, int borderColor)
{
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadii(new float[] { 8, 8, 8, 8, 0, 0, 0, 0 });
shape.setColor(backgroundColor);
shape.setStroke(3, borderColor);
v.setBackground(shape);
}

来源:How to create android shape background programmatically?

关于android - 如何根据 Android Kotlin 中的宽度将圆角应用于 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58019006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com