android - RecyclerView GridLayoutManager: change column width -
i have recyclerview , gridlayoutmanager. columns width equal want first column 80dp
width. possible?
example: recyclerview width 5 columns
final columnscount = 5; recyclerview.width = 500dp column0.width = 80dp column 1-2-3-4 width = (recyclerview.width - column0.width) / columnscount
any advice?
edit: code
public class testrecyclerviewadapter extends recyclerview.adapter<recyclerview.viewholder> { private static final int view_type_start = 0; private static final int view_type_progress_item = 1; private layoutinflater inflater; public testrecyclerviewadapter(context context) { this.inflater = layoutinflater.from(context); } @override public int getitemviewtype(int position) { if (position == 0) { return view_type_start; } else { return view_type_progress_item; } } @override public recyclerview.viewholder oncreateviewholder(viewgroup parent, int viewtype) { final view view; switch (viewtype) { case view_type_start: view = this.inflater.inflate(r.layout.view_item_small, parent, false); return new testviewholder(view); case view_type_progress_item: view = this.inflater.inflate(r.layout.view_item, parent, false); return new testviewholder(view); } return null; } @override public void onbindviewholder(recyclerview.viewholder holder, int position) { } @override public int getitemcount() { return 5; } }
view_item.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#0000ff" android:orientation="vertical">
view_item_small.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="80dp" android:layout_height="match_parent" android:background="#ff0000" android:orientation="vertical">
usage:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); recyclerview recyclerview = (recyclerview) findviewbyid(r.id.recyclerview); recyclerview.setadapter(new testrecyclerviewadapter(this)); recyclerview.setlayoutmanager(new gridlayoutmanager(this, 5)); }
in adapter can that.
check if item's position equals 0, if inflate layout 80dp width.
Comments
Post a Comment