Android Studio - 为什么我的 recycler-view 在不让我滚动到其底部的情况下卡住?
Android Studio - Why does my recycler-view get stuck without letting me scrolling to its bottom?
描述
我正在使用回收器视图,其中的项目比屏幕高度还多,因此要查看它们,我们应该向下滚动。问题是我只能向下滚动一些 dps(例如 10 或 20 dps)。
我需要什么?
我需要滚动到它的底部才能看到所有 回收商的观点。
我的设计是私人的,所以我要给你看一张图:
蓝框是我的回收视图。它加载了十个视图,但我们只能看到两个半。我可以滑动以便看到“Daddy Yankee”的全名,但不能超过这个。
我的片段XML代码(其中有我的回收器)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:contentDescription="@string/ayuda">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:elevation="2dp"
android:contentDescription="@string/ayuda"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="#8d6e63"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageButton
android:id="@+id/imgbt_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:contentDescription="@string/ayuda"
android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/icon_back_negro"
android:tint="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt_lobby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:contentDescription="@string/ayuda"
android:text="Lobby"
android:textColor="#ffffff"
android:textSize="15.5sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/imgbt_back"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/txt_names"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="(10) names"
android:fontFamily="@font/arimo"
android:textColor="#000000"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="@id/constraint_bar"
app:layout_constraintLeft_toLeftOf="parent"
android:contentDescription="@string/ayuda"/>
<View
android:id="@+id/view_barra0"
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_marginTop="5dp"
android:background="#eeeeee"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/txt_names"
android:contentDescription="@string/ayuda"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_names"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/view_barra0"
app:layout_constraintLeft_toLeftOf="parent"
android:contentDescription="@string/ayuda"/>
</androidx.constraintlayout.widget.ConstraintLayout>
如何才能将我的回收器滑到底部以便能够看到所有其他视图?
在您的 id/recycler_names
上添加此约束:
app:layout_constraintBottom_toBottomOf="parent"
然后将layout_height
设置为0dp
(匹配约束)。
描述
我正在使用回收器视图,其中的项目比屏幕高度还多,因此要查看它们,我们应该向下滚动。问题是我只能向下滚动一些 dps(例如 10 或 20 dps)。
我需要什么?
我需要滚动到它的底部才能看到所有 回收商的观点。
我的设计是私人的,所以我要给你看一张图:
蓝框是我的回收视图。它加载了十个视图,但我们只能看到两个半。我可以滑动以便看到“Daddy Yankee”的全名,但不能超过这个。
我的片段XML代码(其中有我的回收器)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:contentDescription="@string/ayuda">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:elevation="2dp"
android:contentDescription="@string/ayuda"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="#8d6e63"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageButton
android:id="@+id/imgbt_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:contentDescription="@string/ayuda"
android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/icon_back_negro"
android:tint="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt_lobby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:contentDescription="@string/ayuda"
android:text="Lobby"
android:textColor="#ffffff"
android:textSize="15.5sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/imgbt_back"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/txt_names"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="(10) names"
android:fontFamily="@font/arimo"
android:textColor="#000000"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="@id/constraint_bar"
app:layout_constraintLeft_toLeftOf="parent"
android:contentDescription="@string/ayuda"/>
<View
android:id="@+id/view_barra0"
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_marginTop="5dp"
android:background="#eeeeee"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/txt_names"
android:contentDescription="@string/ayuda"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_names"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/view_barra0"
app:layout_constraintLeft_toLeftOf="parent"
android:contentDescription="@string/ayuda"/>
</androidx.constraintlayout.widget.ConstraintLayout>
如何才能将我的回收器滑到底部以便能够看到所有其他视图?
在您的 id/recycler_names
上添加此约束:
app:layout_constraintBottom_toBottomOf="parent"
然后将layout_height
设置为0dp
(匹配约束)。