【发布时间】:2019-10-10 20:11:33
【问题描述】:
我有以下 xml:
<?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"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_layout" />
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
android:gravity="center_horizontal"
android:padding="@dimen/dimen_16dp"
android:textSize="@dimen/dimen_16sp" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="visible" />
</RelativeLayout>
我在它下面有一个工具栏和一个 listView。在我填充列表之前,我想在布局的中心显示一个 ProgressBar。我设置了 centerInParent 但它不起作用。进度条显示在工具栏上方。
我尝试将 progressBar 放在 LinearLayout 中,但得到了相同的结果。怎样才能居中?
编辑
这是toolbar_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="@color/colorPrimary"
app:contentInsetStart="0dp">
<ImageButton
android:id="@+id/home"
android:layout_width="@dimen/margin_16dp"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:src="@drawable/ic_arrow_back_black_16dp"
android:layout_marginStart="@dimen/margin_16dp"
tools:ignore="contentDescription" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_16dp"
style="@style/ScreenTitleStyle"
android:textColor="@color/textColorPrimary"/>
</androidx.appcompat.widget.Toolbar>
【问题讨论】:
-
在此处发布您的工具栏布局代码。
-
@MehulSolanki 我编辑了我的问题并添加了相关的工具栏布局。
-
我在下面添加了答案。检查剪断。如果这可行,请取消注释您的工具栏,并删除我使用的工具栏。
标签: android android-layout android-listview android-progressbar android-relativelayout