Android - ProgressBar-Methode setProgress () - Methode funktioniert nicht-update der Fortschrittsbalken drawable
Habe ich ein circular progress bar (0 bis 100) zum anzeigen einer Zeit ausgeführt Fortschritt (von 1:00 bis 0:00). Wenn die Zeit 1:00, der Fortschritt muss 0 sein, wenn die Zeit 0:00, das muss der Fortschritt sein 100.
<ImageView
android:layout_width="@dimen/_56sdp"
android:layout_height="@dimen/_56sdp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/_2sdp"
android:src="@drawable/a_circular_black" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="@dimen/_56sdp"
android:layout_height="@dimen/_56sdp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/_2sdp"
android:max="100"
android:progress="26" //I set the progress 26 to show what it will be look like. Normally for 1:00 the progress must be 0.
android:progressDrawable="@drawable/a_circular" />
<TextView
android:id="@+id/textViewTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/_17sdp"
android:text="1:00"
android:textColor="#000000"
android:textSize="@dimen/_18sdp"
android:textStyle="bold" />
Hier ist die progress-bar hintergrund:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="270"
android:toDegrees="270"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="@dimen/_3sdp" >
<size android:width="@dimen/_56sdp" android:height="@dimen/_56sdp" />
<gradient
android:centerColor="#FFA708"
android:endColor="#FFA708"
android:startColor="#FFA708"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
Hier ist der Bild-hintergrund:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size
android:width="60dp"
android:height="60dp" />
<stroke
android:width="3dp"
android:color="#ccc" />
<padding
android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="3dp" />
</shape>
</item>
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:shape="oval">
<size
android:width="60dp"
android:height="60dp" />
<gradient
android:centerColor="#000"
android:endColor="#000"
android:startColor="#000"
android:type="sweep" />
<padding
android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="3dp" />
</shape>
</rotate>
</item>
<item>
<shape android:shape="oval">
<size
android:width="60dp"
android:height="60dp" />
<solid android:color="#ccc" />
</shape>
</item>
</layer-list>.
Also auf meinem layout-Vorschau erscheint es wie dieses:
In meinem onCreate
ich den Fortschritt 0
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setProgress(0);
Dann, wenn meine Zeit läuft im thread ist, wird der timer aktualisiert sich selbst:
private class TimeRun implements Runnable {
@Override
public void run() {
while (timeLeft > 0) {
try {
Thread.sleep(100);
timeLeft = timeLeft - 100;
} catch (InterruptedException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
progressBar.setProgress(100 - (int) ((double) timeLeft / ((double) 60000) * 100));
if (timeLeft < 10000)
textViewTimer.setText("0:0" + timeLeft / 1000);
else
textViewTimer.setText("0:" + timeLeft / 1000);
}
});
}
}
Wenn ich führen Sie die Aktivität, der Fortschrittsbalken zeigt 100, dachte, es hätte 0 (schwarzer Kreis). Und es zeigt sich keine Veränderung während der Laufzeit. Die text-Ansicht updates normalerweise, aber der Fortschritt-Balken zeigt keine Veränderung.
Die logs zeigen mir, dass der Fortschritt der Aktualisierung, aber grafisch gibt es keine änderungen.
Ich habe versucht, zu aktualisieren, indem Sie ein Runnable, ich habe diese Frage auch, aber die Antworten waren mir nicht helfen
android-progressBar-nicht-update Fortschrittsanzeige/drawable
Können Sie mir empfehlen irgendwelche Lösung?
Ich starten Sie es mit dem timeRun.start(); Der thread funktioniert gut, weil ich den text sehen und die Fortschritte zu aktualisieren (über Protokolle).
Haben Sie versuchen, zu drucken, den Wert, den Sie geben, um
setProgress
bei jeder iteration, um sicherzustellen, dass es geht von 100 auf 0, wie Sie erwarten?Ja, die logs zeigen mir, von 0 auf 100, als ich erwartet hatte.
Sie können ein einfaches Projekt mit, dass Verhalten, ich werde einen Blick zu haben.
InformationsquelleAutor Hayk Abelyan | 2017-04-19
Du musst angemeldet sein, um einen Kommentar abzugeben.
Nehmen Sie einen Blick auf diese Lösung. Es arbeitete.
http://demonuts.com/2017/01/02/android-circular-progress-bar-percentage/
Es ist aufgrund Ihrer Fortschrittsbalken hintergrund.
InformationsquelleAutor slh
Sollten Sie verwenden
CountDownTimer
statt, das wird einfacher als mit einem thread:Wenn es immer noch nicht funktioniert für Sie, dann sollten Sie Synchized() beim aktualisieren der ProgressBar, weil ich immer dasselbe Problem und dieses gelöst, dass :
oder
ProgressBar
war nicht aktualisiert.Immer noch keine änderung. Definitiv, das problem ist-in-progress bar selbst.
ok.. ich update meine Antwort nach dem aufstehen Hauptgrund.
InformationsquelleAutor NehaK
Versuchen, wie diese
InformationsquelleAutor Kishore Jethava