mat*_*ash 5 android android-ui wear-os
我是说这个:

(在单个屏幕截图中看起来不太好,但它比默认的不确定进度要好得多 - 实际上它的形状和动画非常类似于Android L中包含的新"Material"不确定进度,加上它会改变颜色) .
styles.xml19和20平台之间没有差异,虽然有新的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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这可以帮助别人.如果您愿意,可以添加更多属性,但这是我发现的最小解决方案.
| 归档时间: |
|
| 查看次数: |
526 次 |
| 最近记录: |