Android:在布局的中心设置循环进度条

时间:2016-09-28 10:28:20

标签: android android-layout progress-bar

进度条出现在布局的顶部中心,但我想将其对齐在布局的中心。我也尝试过Stackoverflow上的其他答案,但它没有用。这是布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <ProgressBar
    android:id="@+id/progressbar"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_centerInParent="true"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"/>

  <android.support.v7.widget.RecyclerView
    android:id="@+id/dashboard_recyclerview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</RelativeLayout>

2 个答案:

答案 0 :(得分:3)

试试这个

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:id="@+id/dashboard_recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<ProgressBar
    android:id="@+id/progressbar"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_centerInParent="true" />

答案 1 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ProgressBar
        android:id="@+id/progressbar"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerInParent="true"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/dashboard_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</RelativeLayout>

在您获取数据时获取recyclerview可见性,在获取数据后,将progressbar可见性设置为已消失且recyclerview可见性为可见

相关问题