可能做圆角的自定义进度progressDrawable? [英] Possible to do rounded corners in custom Progressbar progressDrawable?

查看:590
本文介绍了可能做圆角的自定义进度progressDrawable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个进度条应该看起来像附图片:

I have a progress bar that is supposed to look like the attached image:

和我做了它一个很长的路要走。我很接近,不工作的唯一部分是圆角的progressDrawable。下面是我的样子。 (注意,红色圆圈,说白了就是轮廓内填充没有圆角):

And I've made it a long way. I'm very close the only part that isn't working is the rounded corners for the progressDrawable. Here is what mine looks like. (Notice, circled in red, that the fill inside the white outline does not have rounded corners):

所以,我发现一对夫妇的方式,使当进度条是有色与形状,渐变,或颜色这项工作。但是,我不能让它与图像作为progressDrawable。

So, I've found a couple of ways to make this work when the progress bar is colored in with a shape, gradient, or color. BUT, I can't get it with an image as the progressDrawable.

下面是我的课扩展进度

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>

下面是选择使用的图像:

Here are the images used in the selector:

slider_track - >
slider_track_progress - >

slider_track->
slider_track_progress->

下面是我嵌入我的布局进度我的活动

Here is where I embed my progressbar in the layout for my 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"
/>

任何人都知道如何使这项工作?

Anyone know how to make this work?

推荐答案

不知道你是否能真正圆了边缘通过API,但你可以很轻松地将白色的轮廓,和你的实际进展对象之间添加一个新图层?该层可以是白色轮廓的精确切口,并因此,进度条不会外轮廓显示。

Not sure if you can actually round out the edges through API, but you could very easily add a new layer between your white outline, and your actual progress object? The layer could be an exact cutout of the white outline, and thus the progress bar would not show outside the outline.

这篇关于可能做圆角的自定义进度progressDrawable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆