我已经制作了一个水平进度条,它运行得非常完美。 我想在其中显示一个类似文本视图的东西,并在加载时显示倒计时。 请记住,这不是进度对话框,进度条驻留在活动内并显示倒计时器。 有人可以帮我吗?如何最好地做到这一点,我该如何实现?
我已经制作了一个水平进度条,它运行得非常完美。 我想在其中显示一个类似文本视图的东西,并在加载时显示倒计时。 请记住,这不是进度对话框,进度条驻留在活动内并显示倒计时器。 有人可以帮我吗?如何最好地做到这一点,我该如何实现?
ProgressBar
和TextView
位于RelativeLayout
中,您可以为ProgressBar
指定一个id,然后使用该id将TextView
与ProgressBar
对齐。这样TextView
就应该显示在ProgressBar
的上方。请确保背景是透明的,以便仍然可以看到ProgressBar
。<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"
android:id="@+id/PROGRESS_BAR"/>
<!-- TextView with transparent background -->
<TextView
android:background="#00000000"
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>
您可以使用FrameLayout在进度条上方显示TextView:
...
<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>
<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>
这是对我有效的方法:
<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>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
map:layout_constraintBottom_toBottomOf="@+id/programStatusTextView"
map:layout_constraintStart_toEndOf="@+id/programStatusTextView"
map:layout_constraintTop_toTopOf="@+id/programStatusTextView">
<RelativeLayout
android:layout_width="130dp"
android:layout_height="60dp"
android:background="@drawable/battery">
<ProgressBar
android:id="@+id/batteryIndicaterBar"
style="@style/CustomProgressBarHorizontal"
android:layout_width="119dp"
android:layout_height="52dp"
android:layout_marginStart="3dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="7dp"
android:backgroundTint="@color/colorPrimary"
android:max="100"
android:minHeight="10dip"
android:paddingEnd="4dp"
android:progress="0"
android:progressBackgroundTintMode="src_over"
android:progressTint="@color/green"
android:visibility="visible" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0"
android:textSize="20sp"
android:textStyle="bold" />
</FrameLayout>
<?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>
android:layout_centerInParent="true"
// 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();
}
请检查其他