'Not able show Top & bottom items in recyclerView
I am using recyclerview in my project but bottom items are not displayed in recyclerview.
I tried ScrollView but my app is crashing it shows java.lang.IllegalStateException: ScrollView can host only one direct child this error.
Here is my code
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyler_transaction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout></FrameLayout>
Solution 1:[1]
I think you use the recyclerview as parent layout that this work is wrong, because recyclerview in android just get a adapter that it, and you most use the container layout like scrollbars for show another layout inside it.
Solution 2:[2]
You have added more than one ViewGroup as a child of your ScrollView. ScrollView must contain at most one child in order to properly calculate the height of the view.
Below sample code is wrong:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
....
....
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
....
....
</LinearLayout>
</ScrollView>
In order to solve the problem, you can use the below sample code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- here add your views -->
....
....
</LinearLayout>
</ScrollView>
Solution 3:[3]
<ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RecyclerView
android:id="@+id/rcview"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
Implement your RecyclerView in this manner. You dont need ScrollView to add recyclerview. Recyclerview can scroll by itself. It will be good of you can add your whole xml and Adapter code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Saeed saednazari |
| Solution 2 | Imran Chowdhury |
| Solution 3 |
