<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottomSheetLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_top_round_corner">
<androidx.cardview.widget.CardView
android:id="@+id/cardViewInnerProductContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:cardElevation="10dp"
app:cardCornerRadius="10dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/closeIv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:src="@drawable/ic_close_dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/changeAddressTitleTv"
style="@style/FontLocalizedBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="7dp"
android:paddingStart="12dp"
android:text="@string/changeaddress_popup_change_address"
android:textColor="@color/colorTextPrimary"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/closeIv" />
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorDividerLight"
app:layout_constraintTop_toBottomOf="@id/closeIv" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/locationRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider"
tools:listitem="@layout/item_choose_address" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/addressesRv"
android:layout_width="match_parent"
android:layout_height="200dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingBottom="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/locationRv"
tools:listitem="@layout/item_choose_address" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
val addressesLayoutManager = LinearLayoutManager(context)
addressesLayoutManager.orientation = RecyclerView.VERTICAL
addressesRv.layoutManager = addressesLayoutManager
addressesRv
recycleView is not scrolling. I have this set in a bottomsheet dialog. It is just taking the 200dp height size and show only the items that fit, and I can not scroll through all items.
I have tried to take out the CardView
, to remove the other recycle in the view, to wrap addressesRv
inside a NestedScrollLayout, but neither one of the cases the scroll worked.
EDIT:
Because you are using multiple Recyclerview
in same page and i think both recyclerView
has LinearLayout manager with vertical orientation. I found your first recycler view height is wrapContent
but second one is fixed. So here it has a change scrolling problem. So here you need nestedScrolview
.
What nestedScrollView
will do?:
Ans : It will help you to scroll both recyclerview.
More discussion about Problem: Suppose your first recyclerView has 10 element and these element cover full screen but your second recyclerView has also 10 element. Now both recyclerView not shwoing all element together. Because the cannot scroll without nestedScrollView
Code sample:
<androidx.cardview.widget.CardView
android:id="@+id/cardViewInnerProductContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:cardElevation="10dp"
app:cardCornerRadius="10dp">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
// Your other code
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
If you put NestedScrollview, remove it.
And add this in your addressesRv recyclerview
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
try this Place your constraint layout in CoOrdinator Layout
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>
How do you add class in your RecyclerView? You must set LayoutManager in class. Example:
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.HORIZONTAL));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.