Android Center Gridview Horizintally in RelativeLayout
I have a GridView which number of columns is determined at runtime, each
column have a width of 50dp, if the columns are not enough to fill the
parent (whole screen), I want the GridView to be centralized in the
parent, I tried a lot of things and the only think that works for me is
putting the gridviews's layout_width to a fixed number, but I really want
it to be wrap_content :(. This is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >
<GridView
android:id="@+id/gridView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:clipChildren="true"
android:columnWidth="50dp"
android:horizontalSpacing="0dp"
android:numColumns="auto_fit"
android:padding="0dp"
android:gravity="center"
android:verticalSpacing="0dp" />
</RelativeLayout>
No comments:
Post a Comment