Dies kann durch Codierung der beiden Indikatoren als primärer Fortschritt und sekundärer Fortschritt derselben Fortschrittsanzeige erfolgen.
erstellen Sie eine Unterklasse für den Fortschrittsbalken.
public class TextProgressBar extends ProgressBar {
private Paint textPaint;
public TextProgressBar(Context context) {
super(context);
textPaint = new Paint();
textPaint.setColor(Color.BLACK);
}
public TextProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
textPaint = new Paint();
textPaint.setColor(Color.BLACK);
setMax(30);
setProgress(12);
setSecondaryProgress(20);
}
}
Der XML-Eintrag für den Fortschrittsbalken muss mit dieser Subklasse referenziert werden.
<com.darsh.doubleProgressBar.TextProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="15sp"
android:layout_marginLeft="1sp"
android:layout_marginRight="1sp"
android:layout_marginTop="10sp"
android:progressDrawable="@drawable/progress" />
schaffen jetzt die ziehbar im Ressourcenverzeichnis
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:startColor="#ff5a5d5a" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#32cd32"
android:centerY="0.75"
android:endColor="#32cd32"
android:startColor="#32cd32" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:endColor="#33B5E5"
android:startColor="#33B5E5" />
</shape>
</clip>
</item>
</layer-list>
Die Farben für die primären und sekundären Indikatoren können in diesem ziehbar geändert werden.
Nutzen Sie sie in Ihrem Code wie folgt aus:
TextProgressBar textProgress;
textProgress = (TextProgressBar)findViewById(R.id.progressBar1);
textProgress.setMax(100);
textProgress.setProgress(10); //
textProgress.setSecondaryProgress(50); //green
2 kurze Fragen: 'android: id = "@ android: id/secondaryProgress"', sollte das 'sein android: id = "@ + id/sekundärProgress" '? Und warum eine Unterklasse erstellen? Sie erstellen ein privates Feld, aber verwenden Sie es nicht. –
Missachten Sie die erste Frage, ich habe es: Sie müssen die ID aus dem Android-Set, so dass die ProgressBar wissen, welche Form zu verwenden. –