android - 如何居中进度条?

标签 android android-layout

它是水平居中而不是垂直居中。我在这里尝试了其他解决方案,但似乎没有用。谁能解释一下我该如何解决这个问题?

<?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/

相关文章:

android - ORMLite 和惰性集合的问题

android - 定期轮询后端 API 一定次数 - Retrofit & RxJava

android - Firebase Cloud Messaging android 项目不发送推送通知

android - 如何在布局下方显示 viewpager?

android - 在 android 中运行启动器 Activity 时出现空指针异常

java - 触摸主 Activity 中的任何位置时无法启动 Activity

android - 如何将 Android ListView 放置在 View 上方 - 不占用全部空间

android - 折叠工具栏和 DrawerLayout

android - 工具栏中抽屉切换的徽章通知 - Android

android - 如何将页脚 View (TextView)添加到 ListView 的末尾?