我有一個ProgressBar
,它是RecyclerView
的一個項目,並且在那裏添加了這個教程Android RecyclerView dynamically load more items when scroll to end with bottom ProgressBar後面的適配器。RecyclerView裏面的Center ProgressBar在ConstraintLayout裏面
但是,使用默認ConstraintLayout
而不是在activity_main.xml
文件中使用RelativeLayout
。對我來說問題是ProgressBar
不居中。
請找我上面所描述的佈局如下:
進度欄項目
<?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="wrap_content"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
的activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="me.bookquotes.quotes.MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
下面是截圖出現在左邊的ProgressBar
(我需要它居中):
我再看看你的問題,不認爲我的答案真的解決了它。當你說進度條不居中時,你的屏幕是什麼樣的?你能發佈一個屏幕截圖嗎? – Cheticamp