Introduction:
This error only happens to me with a single RecyclerView of my application (which has more than 10 recyclers views). Exploring the code, I can't find the reason for this.
Explanation:
I have an activity which has a RecyclerView match parent (width) match parent (height). Inside it there are several elements, so these are below the activity, so the only way to view them is by sliding the RecyclerView.
The problem is here because I want to slide it but I can't.
XML code of my activity:
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee"
android:contentDescription="@string/ayuda">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:contentDescription="@string/ayuda"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
JAVA code of the recycler view
public class fragment extends Fragment{
private RecyclerView recycler_view;
private ArrayList<model_recycler_view> arraylist = new ArrayList<>();
private adapter_recycler_view adaptador_recycler_view;
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, container, false);
recycler_view = view.findViewById(R.id.recycler_view);
DividerItemDecoration did = new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL);
did.setDrawable(getResources().getDrawable(R.drawable.divider_recycler_view));
recycler_view.setLayoutManager(new LinearLayoutManager(getActivity()));
recycler_view.addItemDecoration(did);
arraylist.clear();
llenarRecycler();
adaptador_recycler_view = new adapter_recycler_view(arraylist,getActivity());
recycler_view.setAdapter(adapter_recycler_view);
return view;
}
}
I am attaching an image of what my RecyclerView looks like, which contains 7 views, but you can only see up to 6 and I cannot continue descending to 7.
I really appreciate your reading!
Beware of putting unnecessary ViewGroups or views in the code, they have a cost ;) In this case, since you only have one RecyclerView inside the ConstraintLayout, you can delete the ConstraintLayout and add the resources scheme in the RecyclerView itself:
Anyway, for your example to work, you would have to define the constraint:
And then modify the width and height, from match_parent to 0dp, which is the equivalent of match_constraint: