Android Grid Layout - Even distribution of cells -
i using grid layout show custom views on screen. need show these buttons equally spaced horizontally fill , fit screen. if x number can accommodated in row, move rest row. add new dynamic views in similar fashion.
similar following image on nexus 5
but when check ui smaller screens columns 2 , 3 gone
how can achieve consistent , distribution of icons in grid layout?
code used :
<gridlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:columncount="3" android:paddingleft="7dp" android:paddingtop="7dp" android:paddingbottom="7dp" android:paddingright="3dp" tools:context=".mainactivityfragment"> <com.custom.myview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_columnweight="1" android:layout_margin="2dp"/> <com.custom.myview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_columnweight="1" android:layout_margin="2dp"/> <com.custom.myview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_columnweight="1" android:layout_margin="2dp"/> <com.custom.myview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_columnweight="1" android:layout_margin="2dp" />
i got working , able adapt columns based on screen size using
<integer name="column_numbers">3</integer>
or
<integer name="column_numbers">2</integer>
in different values folders values-normal-hdpi or values-normal-xxhdpi
in layout file add android:columncount="@integer/column_numbers"
fetch correct number of columns respective screen size.
Comments
Post a Comment