android - How to make gridview asymmetric? -
in application trying make gridview asymmetric,but able set colums 2 or 3 on..any other option make gridview asymmetric? following code gridview,can me this?
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f3f3f3" > <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="150dp" /> <gridview android:numcolumns="2" android:gravity="center" android:stretchmode="columnwidth" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/allproduct_grid" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:horizontalspacing="10dp" android:verticalspacing="10dp" android:layout_margintop="10dp" /> </linearlayout>
what want:
you not have native layout or widget achieve this. looking staggeredgridview allows items have variable sizes.
you can do either of following :-
1) can use this or this library. simple use. have used both , can assure work perfectly.
2) can try recyclerview.staggeredgridlayoutmanager google.
a sample code somethings this,
recyclerview recyclerview = (recyclerview) findviewbyid(r.id.recycler_view); recyclerview.setlayoutmanager(new staggeredgridlayoutmanager(2, staggeredgridlayoutmanager.vertical)); recyclerview.setadapter(adapter);
hope helps you.
Comments
Post a Comment