gpt4 book ai didi

android - 可以在自定义 Progressbar progressDrawable 中做圆角吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:08:19 25 4
gpt4 key购买 nike

我有一个进度条,应该看起来像附图:enter image description here

我已经走了很长一段路。我非常接近唯一不起作用的部分是 progressDrawable 的圆角。这是我的样子。 (注意,用红色圈出,白色轮廓内的填充没有圆角):enter image description here

因此,当进度条使用形状、渐变或颜色着色时,我找到了几种方法来完成这项工作。但是,我无法将图像作为 progressDrawable 来获取它。

这是我扩展 ProgressBar 的类

public class RoundedProgressBar extends ProgressBar{
private Paint paint;

public RoundedProgressBar(Context context) {
super(context);
setup();
}

public RoundedProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
setup();
}

public RoundedProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setup(); ;
}

protected void setup()
{
paint = new Paint();
}

@Override
protected synchronized void onDraw(Canvas canvas) {
// First draw the regular progress bar, then custom draw our text
super.onDraw(canvas);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
RectF r = new RectF(0,0,getWidth()-1,getHeight()-1);
canvas.drawRoundRect(r,getHeight()/2,getHeight()/2, paint);
}
}

这是我的选择器:

<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="@android:id/background"
android:drawable="@drawable/slider_track" />
<item
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/slider_track" />
<item
android:id="@android:id/progress"
android:drawable="@drawable/slider_track_progress" />
</layer-list>

以下是选择器中使用的图像:

slider_track-> enter image description here
slider_track_progress-> enter image description here

这是我在 Activity 布局中嵌入进度条的地方

<com.android.component.RoundedProgressBar
android:id="@+id/player_hp_bar"
android:layout_width="fill_parent"
android:layout_height="36dip"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:max="100"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="@drawable/slider_layer_list"
android:progress="20"
android:maxHeight="12dip"
android:minHeight="12dip"
/>

有人知道怎么做吗?

最佳答案

不确定您是否真的可以通过 API 将边缘修圆,但是您可以很容易地在白色轮廓和实际进度对象之间添加一个新层吗?该层可以是白色轮廓的精确剪切,因此进度条不会显示在轮廓之外。

关于android - 可以在自定义 Progressbar progressDrawable 中做圆角吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5669655/

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