I want my RecyclerView
to wrap_content
. I don't want any scrolling inside RecyclerView, it should adjust to the height of inner children. I wan't my parent ScrollView to scroll the content of my activity.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- scrolls a little bit as RecyclerView goes slightly down beyond the screen -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- still scrolls inside -->
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Populate RecyclerView:
myAdapter = new MyAdapter();
layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(myAdapter);
I use RecyclerView
library where wrap_content
issues should be fixed:
dependencies {
compile 'com.android.support:recyclerview-v7:25.0.0'
}
Basically RecyclerView height calculation doesn't work well for me here. RecyclerView still has it's own scroll and ScrollView scrolls a little as well. If I try to set some rediculous RecyclerView height to 1000dp so that it's bigger than height of items in total, scrolls work as needed e.g. RecyclerView doesn't scroll and ScrollView scrolls the activity with all RecyclerView items.
So what did I do wrong? :)
All I needed is to use android.support.v4.widget.NestedScrollView instead of a ScrollView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With