进度条出现在布局的顶部中心,但我想将其对齐在布局的中心。我也尝试过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>
答案 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
可见性为可见