Android - how to change Recyclerview height dynamically? -


i'm stuck issue changing recycler height based on total items. have tried use layout param this:

        viewgroup.layoutparams params = myrecyclerview.getlayoutparams();         params.height = itemheight * numberofitem;         myrecyclerview.requestlayout(); 

or

       viewgroup.layoutparams params = new  recyclerview.layoutparams(..wrap_content, ...wrap_content);;        params.height = itemheight * numberofitem;        myrecyclerview..setlayoutparams(params); 

but didn't work. how can ? please me !

you should use layoutparams of parent's view in setlayoutparams(params).

for example:

<relativelayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     >     <android.support.v7.widget.recyclerview         android:id="@+id/images"         android:layout_width="wrap_content"         android:layout_height="360dp"         >     </android.support.v7.widget.recyclerview>  </relativelayout> 

change layoutparams in code.

  relativelayout.layoutparams lp =             new relativelayout.layoutparams(relativelayout.layoutparams.match_parent, 500);  recyclerview.setlayoutparams(lp); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -