【问题标题】:Android ProgressBar is not aligning in center of layoutAndroid ProgressBar 未在布局中心对齐
【发布时间】:2014-02-09 06:12:35
【问题描述】:

我在抽屉布局中使用进度条。当我启动应用程序时,进度条总是与屏幕的左上角对齐。我试图设置 android:layout_gravity 属性,但它仍然显示在左上角。下面是我的xml布局文件。

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <FrameLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"    >

        <ProgressBar
            android:id="@+id/progressBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"            
            android:visibility="gone"
            style="?android:attr/progressBarStyleLarge" />

        <ListView 
            android:id="@+id/mainListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

    </FrameLayout>

    <ListView android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:dividerHeight="0dp"
            android:background="#FFF"/>
</android.support.v4.widget.DrawerLayout>

【问题讨论】:

    标签: android progress-bar navigation-drawer android-framelayout


    【解决方案1】:

    FrameLayout 上使用android:gravity="&lt;whatever&gt;",因为其中只有进度条。
    此外,您的抽屉将成为列表视图,因为这是具有 layout_gravity="start" 属性集的内容。如果您希望进度条位于左侧抽屉中,您可以将进度条和列表视图包装到一个容器中并在其上设置layout_gravity="start"
    没有进一步的解释,这就是我能帮助的。

    【讨论】:

    • 感谢您的快速回复,但设置 layout_gravity="center" 。框架布局不显示。只有抽屉出现。
    • 您应该更改 xml 中项目的顺序。将 ListView 放在 FrameLayout 之前。
    【解决方案2】:

    这对我有用。在 FrameLayout 集合中

    android:layout_centerInParent="true"
    

    【讨论】:

      【解决方案3】:

      请试试这个代码,这个代码对我有用。

      ProgressBarView.xml

      <?xml version="1.0" encoding="utf-8"?>
      <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/progressBar"
          android:layout_gravity="center"
          android:orientation="vertical">
      
      </ProgressBar>
      

      现在将此布局包含到 NavigationView 中,

      <android.support.design.widget.NavigationView
          android:id="@+id/nav_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:fitsSystemWindows="true">
            <include layout="@layout/progress_bar"/>
      </android.support.design.widget.NavigationView>
      

      在 Studio 中预览

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多