5

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'
}

enter image description here

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? :)

Andrei
  • 42,814
  • 35
  • 154
  • 218
  • Was this working before v25? – natario Nov 13 '16 at 14:31
  • Please go through this link you can find the solution[enter link description here](http://stackoverflow.com/questions/30531091/how-to-disable-recyclerview-scrolling) – Kiran Nemani Nov 13 '16 at 14:35
  • @natario afaik there were bugs in >v23 but they were fixed and wrap_content should work as expected. – Andrei Nov 13 '16 at 14:40
  • @KiranNemani I don't want to disable scrolling in RecyclerView. I want it to wrap_content of it's inner children. – Andrei Nov 13 '16 at 14:41

2 Answers2

4

All I needed is to use android.support.v4.widget.NestedScrollView instead of a ScrollView.

Andrei
  • 42,814
  • 35
  • 154
  • 218
0

In that case you need to upgrade your recyclerview gradle version, if you are using 23.0.1 make it 23.1.1 or higher version. In the latest gradle update google has provided the wrap_content property to recyclerview.

Kiran Nemani
  • 67
  • 1
  • 6
  • By default recyclerview comes with scroll feature. What i understand from your question is your recyclerview shouldn't scroll and along with that you need to resize the recyclerview with wrap_content option. Is it ? recently i faced the same situation with wrap_content issue in recylerview, that time i upgraded my recyclerview gradle version. If you are not satisfied tell me i will suggest better one. – Kiran Nemani Nov 13 '16 at 17:26
  • 1
    well, yes, I don't want recyclerview to scroll, but not literally, I want it to be of the height of all it's children (e.g. wrap_content), but the problem is, wrap content is not working for me for some reason. I get items from http, populate them in adapter, call `notifyDataSetChanged()`. And... RecyclerView is not of it's full height and I can scroll inside of it. Gradle and Support libs are all up to date. – Andrei Nov 13 '16 at 17:47