I have a GridView
, which displays pictures of alphabets
what happens is , every time in the last row there are less no of alphabets.
and the last row is left aligned , which doesn't look good
so I want make the last row to be in centre,
any suggestion
My GridView
code:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="70dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="20dp"
android:gravity="center"
android:stretchMode="spacingWidthUniform" >
</GridView>
GridView
with another adapter that will insert some extra dummy elements(if needed) so your last items will be centered. – HouseraisingViewTreeObserver
and see in there how many columns theGridView
is using(getNumColumns()
) and then trigger an adapter change(adding elements if needed) based on that value. Be careful to not get yourself in an endless loop. – Houseraising