繁体   English   中英

Android Wear中的“漂亮”不确定进度指示器是否有预构建的资源/小部件?

[英]Is there a prebuilt resource/widget for the “nice” indeterminate progress indicator in Android Wear?

我是说这个:

在此输入图像描述

(在单个屏幕截图中看起来不太好,但它比默认的不确定进度要好得多 - 实际上它的形状和动画非常类似于Android L中包含的新“Material”不确定进度,加上它会改变颜色) 。

在19和20个平台之间, styles.xml没有区别,虽然有一个新的styles_micro.xml ,但它似乎不包括这个。

需要和你一样的东西。 不确定你是否找到了一个解决方案,它是android的一部分。 由于我没有找到解决方案,我确实建立了自己的解决方案。 它并不完美,但只要你不逐帧研究,它看起来应该是正确的。

我创建了它自己的视图。 代码并不完美,如果有人想改进它,请继续。

public class ProgressView extends ProgressBar {
    RectF rectF;
    Paint p;
    int start = 0;
    int maxvalue = 320;
    int value = 320;
    int[] currentColor = {0,0,0};
    boolean reverse = false;
    int nextcolor = 1;

    final int[][] colors = {
        {224,187,63},
        {224,46,25},
        {39,105,227},
        {51,130,49}
    };

    public ProgressView(Context context) {
        super(context);
        init();
    }

    public ProgressView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ProgressView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init(){
        p = new Paint();
        p.setStrokeWidth(6);
        p.setStrokeCap(Paint.Cap.ROUND);
        p.setAntiAlias(true);
        p.setStyle(Paint.Style.STROKE);
        p.setColor(Color.argb(255,colors[0][0], colors[0][1], colors[0][2]));
        currentColor = Arrays.copyOf(colors[0], colors[0].length);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        rectF = new RectF(0+5, 0+5, w-5, h-5);
    }

    @Override
    protected void onDraw(Canvas c){
        if(reverse)
            start += 15;
        else
            start += 5;

        if(start == 360){
            start = 1;
        }
        if(!reverse)
            value -= 10;
        else
            value += 10;
        if(value == 0 || value == maxvalue){
            reverse = !reverse;
        }
        transformColor();
        p.setColor(Color.argb(255,currentColor[0], currentColor[1], currentColor[2]));
        c.drawArc(rectF, start, maxvalue - value, false, p);
        invalidate();
    }

    private void transformColor(){
        changeColors(0);
        changeColors(1);
        changeColors(2);
        if(currentColor[0] == colors[nextcolor][0] && currentColor[1] == colors[nextcolor][1] && currentColor[2] == colors[nextcolor][2]){
            if(nextcolor == 3)
                nextcolor = 0;
            else
                nextcolor++;
        }
    }

    private void changeColors(int i){
        if(currentColor[i] > colors[nextcolor][i]){
            currentColor[i] -= 1;
        }
        if(currentColor[i] < colors[nextcolor][i]){
            currentColor[i] += 1;
        }
    }
}

我希望这可以帮助别人。 如果您愿意,可以添加更多属性,但这是我发现的最小解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM