Android 如何在不确定进度条(旋转轮)的中心显示文本?
如何在不确定进度条(旋转轮)的中心显示文本 我想在中间显示秒数。使用安卓API-19。 他们说,为了显示进度,必须使用单杠。 但是,如果我可以在中间显示文本,那么这对我来说就行了 那么,我该如何设置文本以显示在纺车进度条中呢 (我更愿意在运行之前尝试使用现有API来构建自定义进度条)Android 如何在不确定进度条(旋转轮)的中心显示文本?,android,Android,如何在不确定进度条(旋转轮)的中心显示文本 我想在中间显示秒数。使用安卓API-19。 他们说,为了显示进度,必须使用单杠。 但是,如果我可以在中间显示文本,那么这对我来说就行了 那么,我该如何设置文本以显示在纺车进度条中呢 (我更愿意在运行之前尝试使用现有API来构建自定义进度条) 将此文本添加到布局中 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
将此文本添加到布局中
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5 s"
android:id="@+id/txt_secondsleft"
android:layout_alignRight="@+id/progressBar1"
android:layout_alignLeft="@+id/progressBar1"
android:gravity="center"
android:layout_alignBottom="@+id/progressBar1"
android:layout_alignTop="@+id/progressBar1"
/>
您可以使用它来显示所需的文本,它将位于进度条的中心我已经尝试并找到了解决方案。使用xml,它将对齐轮子中心的文本。希望这对你有帮助
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ProgressBar
android:id="@+id/prograss_bar"
style="@android:style/Widget.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="loading" />
</RelativeLayout>
在中添加文本视图XML@pedro哪里请参见上面的xml,progressbar父级是什么类型的布局?@pedro我对布局很灵活-可以将其更改为任何工作。太好了!我没有意识到文本视图可以通过设置布局对齐值显示在控制盘的中心。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ProgressBar
android:id="@+id/prograss_bar"
style="@android:style/Widget.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="loading" />
</RelativeLayout>