2014-07-07 23 views
5

Yani bu bir:Android Wear'da "güzel" belirsiz ilerleme göstergesi için önceden oluşturulmuş bir kaynak/widget var mı?

enter image description here

(tek ekran görüntüsünde olduğu gibi güzel görünüyorlar, ama varsayılan belirsiz ilerleme çok daha iyi değildir - aslında şekli ve animasyon oldukça benzerdir Android L'de bulunan yeni "Materyal" belirsiz ilerleme, artı renkleri değiştirir).

19 ve 20 platformlar arasında styles.xml arasında hiçbir fark yoktur ve yeni bir styles_micro.xml olduğu halde, bunu içermiyor gibi görünmektedir.

cevap

7

Sizinle aynı şeylere ihtiyaç duydu. Android kullanımının bir parçası olan bir çözüm bulup bulmadığınızdan emin değilsiniz. Bir çözüm bulamadığım için kendi başıma inşa ettim. Mükemmel değildir, ancak çerçeveyi çerçeveyle çalışmadığınız sürece doğru görünmelidir.

Kendi görünümü olarak oluşturdum. Kod mükemmel değildir ve eğer geliştirmek isteyen biri varsa devam edin.

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; 
     } 
    } 
} 

Umarım bu birilerine yardımcı olabilir. İsterseniz buna daha fazla özellik ekleyebilirsiniz, ancak bu, çalıştığım minimum çözümün bir türüdür.

+0

Harika görünüyor. Paylaşım için teşekkürler –

+0

Harika! Onu varsayılan Lollipop birinden daha çok seviyorum! –

İlgili konular