它是水平居中而不是垂直居中。我在这里尝试了其他解决方案,但似乎没有用。谁能解释一下我该如何解决这个问题?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" />
</LinearLayout>
最佳答案
将 android:gravity="center"
添加到 LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" />
</LinearLayout>
http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:gravity
Specifies how an object should position its content, on both the X and Y axes, within its own bounds.
关于android - 如何居中进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22942796/