android - RecyclerView to be Scrolled horizontally with the width -
i have more items show in cardview horizontally inside recyclerview , have more cards veritically.
i tried place cardview inside horizontalscrollview, worked scroll idividual card. wanted scroll entire recyclerview scrolled see right end items.
i tried recyclerview inside horizontalscroolview not worked. recyclerview inside nestedscrollview not worked.
the recyclerview in fragment. inside viewpager tablayout, 1 of fragment
fragment xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <android.support.v7.widget.recyclerview android:id="@+id/record_recycler" android:layout_width="550dp" android:scrollbars="horizontal" android:layout_height="0dp" android:layout_weight="1" /> </linearlayout>
adapter:
public class testadapter extends recyclerview.adapter{ private list<model> items; context context; public testadapter(context con, list<model> itemslist) { context=con; this.items = itemslist; } @override public int getitemviewtype(int position) { return items.get(position).getunique(); } @override public recyclerview.viewholder oncreateviewholder(viewgroup parent, int viewtype) { if(viewtype==0) return new myviewholder(layoutinflater.from(parent.getcontext()).inflate(r.layout.cricketrank_record_valuecard, parent, false)); else return new myviewholder1(layoutinflater.from(parent.getcontext()).inflate(r.layout.cricketrank_record_titlecard, parent, false)); } @override public void onbindviewholder(recyclerview.viewholder holder, int position) { if (holder instanceof myviewholder) try{ ((myviewholder)holder).bindviewholder(position); }catch (exception e){ log.e(constant.tag,e.tostring()); } else if(holder instanceof myviewholder1) try{ ((myviewholder1)holder).bindviewholder(position); }catch (exception e){ log.e(constant.tag,e.tostring()); } } @override public int getitemcount() { return items.size(); } public class myviewholder extends recyclerview.viewholder{ public textview text,text1,text2,text3,text4,text5; public view mcardview; public myviewholder(view view) { super(view); text1 = (textview) view.findviewbyid(r.id.text1); text2 = (textview) view.findviewbyid(r.id.text2); text3 = (textview) view.findviewbyid(r.id.text3); text4 = (textview) view.findviewbyid(r.id.text4); } public void bindviewholder(int position) { text1.settext(items.get(position).getteam()); text2.settext(items.get(position).getrank()); text3.settext(items.get(position).getmatches()); text4.settext(items.get(position).getpoints()); } } } public class myviewholder1 extends recyclerview.viewholder{ public textview text,text1,text2,text3,text4,text5; public relativelayout rl; public myviewholder1(view view) { super(view); text = (textview) view.findviewbyid(r.id.text); text1 = (textview) view.findviewbyid(r.id.text1); text2 = (textview) view.findviewbyid(r.id.text2); text3 = (textview) view.findviewbyid(r.id.text3); text4 = (textview) view.findviewbyid(r.id.text4); rl = (relativelayout) view.findviewbyid(r.id.rl); } public void bindviewholder(int position) { text1.settext(items.get(position).getteam()); text2.settext(items.get(position).getrank()); text3.settext(items.get(position).getmatches()); text4.settext(items.get(position).getpoints()); } } }
mainactivity:
recyclerview record_recycler= (recyclerview) view.findviewbyid(r.id.record_recycler); recyclerview.layoutmanager mlayoutmanager = new linearlayoutmanager(getactivity()); record_recycler.setlayoutmanager(mlayoutmanager); record_recycler.setitemanimator(new defaultitemanimator()); testadapter adapter = new testadapter(getactivity(), list); record_recycler.setadapter(adapter);
i think trying scroll recyclerview in 2 direction. vertical usual scroll of recylerview , in horizontally, scrolling view if not fit mentioned width. right?
if trying this, think not possible scroll think. can scroll recycler view in both directions different views holding on them.
as said scrolling of cardview possible, default won't have scrolling normally. scroll show card content user if not seeing , set scrolling view scroll.
the possible way is, keep views vertically field name , value. if want create more, add 1 more row accommodate values down.
have below:
<android.support.v7.widget.cardview android:id="@+id/card" android:layout_margintop="2dp" android:layout_marginbottom="4dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <linearlayout android:id="@+id/layout2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/layout1" android:orientation="horizontal"> <textview android:text="one" android:textsize="@dimen/font_itemsrow_13dp" android:layout_weight=".11" android:paddingleft="3dp" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:text="two" android:textsize="@dimen/font_itemsrow_13dp" android:layout_weight=".11" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:text="three" android:textsize="@dimen/font_itemsrow_13dp" android:layout_weight=".24" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:text="four" android:textsize="@dimen/font_itemsrow_13dp" android:layout_weight=".11" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:text="five" android:textsize="@dimen/font_itemsrow_13dp" android:layout_weight=".17" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:text="six" android:textsize="@dimen/font_itemsrow_13dp" android:layout_weight=".26" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> </linearlayout> <linearlayout android:id="@+id/layout3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="@dimen/padding_3dp" android:layout_below="@+id/layout2" android:orientation="horizontal"> <textview android:id="@+id/one" android:textsize="@dimen/font_itemsrow_14dp" android:textcolor="@color/black" android:layout_weight=".11" android:paddingleft="3dp" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:id="@+id/two" android:textsize="@dimen/font_itemsrow_14dp" android:textcolor="@color/black" android:layout_weight=".11" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:id="@+id/three" android:textsize="@dimen/font_itemsrow_14dp" android:textcolor="@color/black" android:layout_weight=".24" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:id="@+id/four" android:textsize="@dimen/font_itemsrow_14dp" android:textcolor="@color/black" android:layout_weight=".11" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:id="@+id/five android:textsize="@dimen/font_itemsrow_14dp" android:textcolor="@color/black" android:layout_weight=".17" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> <textview android:id="@+id/six" android:textsize="@dimen/font_itemsrow_14dp" android:textcolor="@color/black" android:layout_weight=".26" android:paddingright="3dp" android:layout_width="0dp" android:layout_height="wrap_content" /> </linearlayout> <linearlayout ....// add title row </linearlayout> <linearlayout ....// add values row </linearlayout> </relativelayout> </android.support.v7.widget.cardview>
Comments
Post a Comment