gpt4 book ai didi

java - 在相对布局中水平和垂直居中进度条

转载 作者:行者123 更新时间:2023-12-01 11:48:03 24 4
gpt4 key购买 nike

我正在尝试实现以下进度对话框(没有文本)

enter image description here

我当前的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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com