[英]how to show progress bar center of screen
My code show space on top of listview (see left image).我的代码在列表视图顶部显示空间(见左图)。 If I remove
android:gravity="center"
then it will show correctly (see right image)如果我删除
android:gravity="center"
那么它会正确显示(见右图)
But ProgressBar does not display on center of screen, it's displayed on the left of screen.但是 ProgressBar 不显示在屏幕中央,它显示在屏幕左侧。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ListView
android:id="@+id/listCategory2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="true"
android:fastScrollEnabled="true"
android:divider="@color/background"
android:dividerHeight="1dp"
android:visibility="gone"
android:background="@drawable/border9"
android:listSelector="@drawable/listview_selector" />
<ProgressBar
android:id="@+id/prgLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Inverse"
android:layout_centerInParent="true" />
<TextView
android:id="@+id/txtAlert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/alert"
android:textColor="@color/text"
android:textSize="14sp"
android:layout_centerInParent="true"
android:visibility="gone" />
</LinearLayout>
The parent layout which you have taken is LinearLayout and the method in your xml android:layout_centerInParent="true" works for RelativeLayout.您采用的父布局是 LinearLayout 并且您的 xml android:layout_centerInParent="true" 中的方法适用于 RelativeLayout。 You need to change it to android:layout_gravity="center".
您需要将其更改为 android:layout_gravity="center"。 You can instead change the parent layout to RelativeLayout.
您可以改为将父布局更改为 RelativeLayout。
You can use <FrameLayout>
, it really good for you.你可以使用
<FrameLayout>
,它真的对你有好处。
And set progressbar (need match_parent
for layout_width
and layout_height
) as :并将进度条(
layout_width
和layout_height
需要match_parent
)设置为:
<ProgressBar
android:id="@+id/prgLoading"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@android:style/Widget.ProgressBar.Inverse"
android:layout_centerInParent="true"/>
Hope to help,希望有所帮助,
使其成为RelativeLayout
而不是LinearLayout
,并为ListView
添加android:layout_alignParentTop="true"
并为进度条添加android:layout_centerInParent="true"
<ProgressBar
android:id="@+id/loading_spinner"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
/>
For Linear layout对于线性布局
Simple way to center it inside a ConstraintLayout
在
ConstraintLayout
其居中的简单方法
<androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/myProgress"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.