1

i am implementing recyclerview inside scrollview

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusableInTouchMode="true"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:divider="@android:color/transparent"
                android:dividerHeight="0dp"
                android:listSelector="@android:color/transparent" />
        </LinearLayout>

set recyclerview to fixed height like this

    mRecyclerView_other.setHasFixedSize(true);
    RecyclerView.LayoutManager layoutManager_other = new LinearLayoutManager(context);
    mRecyclerView_other.setLayoutManager(layoutManager_other);
    int adapterItemSize = 64;
    int viewHeight = adapterItemSize * list.size();
    mRecyclerView_other.getLayoutParams().height = viewHeight;
    mRecyclerView_other.setAdapter(adapter_other);

as holder height will be fixed to 64dp i have put adapterItemSize = 64, but the issue i am facing is only two rows from the list are visible.

nayana bhoj
  • 115
  • 1
  • 11

1 Answers1

2

I think you have not setLayoutParams. When you change the layout params of a view, you need to set it, eg, this is how you set it for your recyclerview:

 LinearLayout.LayoutParams layoutParams  = mRecyclerView_other.getLayoutParams();
layoutParams.width = 64;
layoutParams.height = 64;
 mRecyclerView_other.setLayoutParams(layoutParams);

You are also setting your width and height using integer values instead of pulling them from the dimens.xml - try this:

In your dimens.xml file:

<dimen name="test">64dp</dimen>

Then extract the int value like this:

int valueInPixels = (int) getResources().getDimension(R.dimen.test)
Simon
  • 19,658
  • 27
  • 149
  • 217
  • didn't worked for me as i need to set height for adapter Item of recyclerview – nayana bhoj Jan 16 '16 at 09:20
  • You are trying to set the recyclerview layoutParams so that the recyclerview equals to the height of the sum of all your items within your recyclerview. It should work for you, I will change the code above quickly so it fits to your scenario - please try again. – Simon Jan 16 '16 at 09:23
  • you did change the layoutParams.height = adapterItemSize * list.size(); right? and layoutParams.width = LayoutParams.MATCH_PARENT? – Simon Jan 16 '16 at 09:53
  • Try to take out the linearlayout in the xml and just wrap the recyclerview with the scrollview and then you will have to set the Scrollview.LayoutParams – Simon Jan 18 '16 at 05:34
  • Also, I was looking at your question again now and I noticed you are setting your height to an int value instead of dp. There is a method to convert int to dp that I use. I will find it later and post here. Just at work – Simon Jan 18 '16 at 05:48
  • i am referring this link http://stackoverflow.com/questions/27083091/recyclerview-inside-scrollview-is-not-working – nayana bhoj Jan 18 '16 at 07:17