android - Use RecyclerView inside ScrollView with fixed Recycler item height -


i 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 fixed height 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 fixed 64dp have put adapteritemsize = 64, issue facing 2 rows list visible.

i think have not setlayoutparams. when change layout params of view, need set it, eg, how set recyclerview:

 linearlayout.layoutparams layoutparams  = mrecyclerview_other.getlayoutparams(); layoutparams.width = 64; layoutparams.height = 64;  mrecyclerview_other.setlayoutparams(layoutparams); 

you setting width , height using integer values instead of pulling them dimens.xml - try this:

in dimens.xml file:

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

then extract int value this:

int valueinpixels = (int) getresources().getdimension(r.dimen.test) 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -