java - RecyclerView space between items expanding when scrolling -
i finished recyclerview
android application
, when testing out, found strange bug don't understand. when activity launches, items in recycler
view positioned in recyclerview
@ correct distances. however, once start scrolling move apart each other until 1 item visible @ once, , have scroll distance equivalent
of screen before seeing next item.
here bug looks like:
before scrolling on activity lunch
after scrolling recycleview
if have idea might causing this, appreciated.
here recyclerview code activity:
private arraylist<string> imagesurllistthumb, imagesurllistfull = new arraylist<string>(); private recycleradapter recycleradapter; private string urlrecyclerthumb = ""; private recyclerview recyclerview; private imageview imgcurrecyclerview; imagesurllistthumb = produit.getimgurlthumbmul(); recycleradapter = new recycleradapter(getapplicationcontext(), imagesurllistthumb); recyclerview = (recyclerview) findviewbyid(r.id.content_product_detail_recycer_view); recyclerview.layoutmanager recyclerlayoutmanager = new linearlayoutmanager(getapplicationcontext(), linearlayoutmanager.horizontal, false); recyclerview.setlayoutmanager(recyclerlayoutmanager); recyclerview.setadapter(recycleradapter); urlrecyclerthumb = imagesurllistthumb.get(0); recycleritemclicksupport.addto(recyclerview).setonitemclicklistener(new recycleritemclicksupport.onitemclicklistener() { @override public void onitemclicked(recyclerview rv, int pos, view view) { urlrecyclerthumb = imagesurllistthumb.get(pos); picasso.with(getapplicationcontext()).load(urlrecyclerthumb).fit().into(imgcurrecyclerview); } });
recycler adapter:
public class recycleradapter extends recyclerview.adapter<recycleradapter.myviewholder>{ private list<string> urlthumbimg; private context context; public recycleradapter(context ctx, list<string> urls){ this.urlthumbimg = urls; this.context = ctx; } @override public recycleradapter.myviewholder oncreateviewholder(viewgroup parent, int viewtype){ view itemview = layoutinflater.from(parent.getcontext()).inflate(r.layout.item_list_slideshow, parent, false); return new myviewholder(itemview); } @override public void onbindviewholder(recycleradapter.myviewholder holder, int position){ string current = urlthumbimg.get(position); picasso.with(context).load(current).fit().into(holder.myimgview); } @override public int getitemcount(){ return urlthumbimg.size(); } public class myviewholder extends recyclerview.viewholder { public imageview myimgview; public myviewholder(view view){ super(view); myimgview = (imageview) view.findviewbyid(r.id.imageview_slide); } } }
here xml layout concerning recycler view:
<!-- recycler view --> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margintop="15dp" android:orientation="vertical"> <imageview android:id="@+id/content_product_detail_recycer_view_cur_image" android:layout_width="150dp" android:layout_height="130dp" android:layout_gravity="center" android:background="@android:color/black" /> <android.support.v7.widget.recyclerview android:id="@+id/content_product_detail_recycer_view" android:layout_width="wrap_content" android:layout_height="60dp" android:layout_gravity="center" android:layout_margin="5dp" android:background="@android:color/darker_gray"> </android.support.v7.widget.recyclerview> </linearlayout>
layout item inside recyclerview:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <imageview android:id="@+id/imageview_slide" android:layout_width="60dp" android:layout_height="60dp" android:layout_margin="5dp" android:background="@android:color/darker_gray" />
provide layout , recyclerview code debug , not make guess.
ok here issue:
with release 2.3.0 there exciting new feature layoutmanager api: auto-measurement! allows recyclerview size based on size of contents. means unavailable scenarios, such using wrap_content dimension of recyclerview, possible. you’ll find built in layoutmanagers support auto-measurement.
due change, make sure double check layout parameters of item views: previously ignored layout parameters (such match_parent in scroll direction) respected.
basically need remove linearlayout
<imageview android:id="@+id/imageview_slide" android:layout_width="60dp" android:layout_height="60dp" android:layout_margin="5dp" android:background="@android:color/darker_gray" />
the match_parent in linearlayout width causing each item fit entire screen 1 image , remaining space.
if insist on using linearlayout, set both width , height wrap_content
Comments
Post a Comment