Monday, 15 April 2013

android - Set height of children in RecyclerView? -



android - Set height of children in RecyclerView? -

i trying utilize recyclerview in similar way viewpager (vertical).

i have setup fling , scroll gestures views scrolled in same way viewpager setup children views (linearlayoutmanager) , linearlayout used each kid view fill screen instead of wrap_content. have made views match_parent , fill_parent not work.

i did this:

holder.layout.setminimumheight(this.recyclerview.getmeasuredheight());

which nice when orientation changes layout overflows screen makes smooth scrolling/gestures flicker etc. don't want overflow screen.

any tips how create children laid out maximum height of screen not overflow?

thanks

edit: changed setting minimum height this:

holder.layout.setlayoutparams(new linearlayout.layoutparams(viewgroup.layoutparams.match_parent, this.recyclerview.getheight()));

which solves flickering issue there improve way?

i have low reputation unable comment down. thats why answering here .

to on come overflow issue lets have xml of single item

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" android:id="@+id/mainlayout" > <-- views --->> </relativelayout>

now in adapter layout in viewholder

and create boolean variable setting adabpter.. can utilize knowing orientation changed . when orientation changed alter value .

in adapter create function public void orientaiotnchange(){ notifydatasetchanged(); }

in function

@override public void onbindviewholder(final viewholder viewholder, final int arg1) { if(isorientationhorizontal){ viewholder.mainlayout.setorientation(horizontal); } else{ viewholder.mainlayout.setorientation(vertical); }

also alter orientation of recyclerview in activity set adapter , checking orientation changed or not .

hopefully work :)

android android-5.0-lollipop recyclerview

No comments:

Post a Comment