Ich habe bereits einen horizontalen Fortschrittsbalken erstellt und er funktioniert perfekt. Ich möchte eine Textansicht oder etwas Ähnliches in der Mitte anzeigen, die einen Countdown anzeigt, während der Balken geladen wird. Beachten Sie, dass es sich nicht um einen Fortschrittsdialog handelt. Die Fortschrittsleiste befindet sich in einer Aktivität und zeigt einen Countdown-Timer. Kann mir jemand helfen, was ist der beste Weg, dies zu tun und wie kann ich das erreichen?
Wenn sich ProgressBar
und TextView
in einem RelativeLayout
befinden, können Sie dem ProgressBar
eine ID zuweisen und das TextView
dann mit dem ProgressBar
ausrichten. Es sollte dann auf der ProgressBar
angezeigt werden. Vergewissern Sie sich, dass der Hintergrund transparent ist, damit Sie die ProgressBar
noch sehen können.
Zum Beispiel:
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
xmlns:tools="http://schemas.Android.com/tools"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
>
<ProgressBar
Android:layout_width="match_parent"
Android:layout_height="match_parent"
// other attributes
Android:id="@+id/PROGRESS_BAR"
>
<TextView
Android:background="#00000000" // transparent
// other attributes
Android:layout_alignLeft="@id/PROGRESS_BAR"
Android:layout_alignTop="@id/PROGRESS_BAR"
Android:layout_alignRight="@id/PROGRESS_BAR"
Android:layout_alignBottom="@id/PROGRESS_BAR"
>
</RelativeLayout>
Sie können ein FrameLayout verwenden, um die TextView über der Fortschrittsleiste anzuzeigen:
...
<FrameLayout
Android:layout_width="match_parent"
Android:layout_height="match_parent">
<ProgressBar
Android:id="@+id/progress"
style="@Android:style/Widget.ProgressBar.Horizontal"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:progressDrawable="@drawable/progressbar" />
<RelativeLayout
Android:layout_width="match_parent"
Android:layout_height="match_parent">
<TextView
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_centerVertical="true" />
...
</RelativeLayout>
</FrameLayout>
das hat für mich funktioniert:
<RelativeLayout
Android:layout_width="match_parent"
Android:layout_height="match_parent">
<ProgressBar
Android:id="@+id/progressBar"
style="@Android:style/Widget.ProgressBar.Horizontal"
Android:progressDrawable="@drawable/customprogressbar"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:max="100"/>
<TextView
Android:id="@+id/progressBarinsideText"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_alignParentLeft="true"
Android:layout_alignParentRight="true"
Android:layout_centerVertical="true"
Android:gravity="center"
/>
</RelativeLayout>
So habe ich Fortschrittstext über einem Spinner in einer Webansicht angezeigt:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:layout_width="match_parent"
Android:layout_height="match_parent">
<WebView
Android:id="@+id/help_webview"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
Android:background="#F22"
Android:scrollbars="none" />
<ProgressBar
Android:id="@+id/progressBar"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_centerHorizontal="true"
Android:layout_centerInParent="true"
Android:layout_centerVertical="true" />
<TextView
Android:id="@+id/progressBarMessage"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:text="Loading, please wait..."
Android:layout_centerInParent="true"
Android:layout_above="@id/progressBar"
Android:background="#00000000" />
</RelativeLayout>
In Activity können wir ProgressBar mit den folgenden Methoden anzeigen und abweisen
// Method to show Progress bar
private void showProgressDialogWithTitle(String substring) {
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//Without this user can hide loader by tapping outside screen
progressDialog.setCancelable(false);
progressDialog.setMessage(substring);
progressDialog.show();
}
// Method to hide/ dismiss Progress bar
private void hideProgressDialogWithTitle() {
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.dismiss();
}
Überprüfen Sie andere
Sie können ein LinearLayout mit RelativeLayout setzen und das RelativeLayout Höhe & Breite gleich wrap_content dann fügen Sie in der Textansicht unter der ProgressBar Android hinzu: layout_centerInParent = "true"
Beispiel
<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:orientation="vertical">
<RelativeLayout
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_gravity="center">
<ProgressBar
Android:id="@+id/progressBar"
Android:layout_width="200dp"
Android:layout_height="200dp"
Android:max="100"
Android:progress="65" />
<TextView
Android:layout_height="wrap_content"
Android:layout_width="wrap_content"
Android:layout_centerInParent="true"
Android:textColor="@color/white"
Android:text="6:00 AM"
Android:textSize="25sp"
Android:textStyle="bold"/>
</RelativeLayout>
</LinearLayout>