我正在尝试实现以下进度对话框(没有文本)
我当前的XML代码如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background"
>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:visibility="gone"
/>
我在需要时以编程方式隐藏和显示进度条(并隐藏/显示其他屏幕元素),所有这些都位于上面 XML 代码中的相对布局下。
但是,每当进度条显示时,它都会显示在屏幕顶部居中,而不是水平和垂直居中。
最佳答案
将 ScrollView 的属性“fillViewport”设置为 true 就可以了。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical"
android:fillViewport="true"
>
还要确保其子项的高度设置为“fill_parent”并且 ProgressBar 正确居中
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
关于java - 在相对布局中水平和垂直居中进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29001044/