How do I center a GridView in its LinearLayout parent ?
Posted
by Jacques René Mesrine
on Stack Overflow
See other posts from Stack Overflow
or by Jacques René Mesrine
Published on 2009-10-09T15:12:24Z
Indexed on
2010/03/22
18:01 UTC
Read the original article
Hit count: 862
GridView is not behaving like it is supposed to. This screenshot shows that the GridView (in landscape mode) is flushed left. I want it centered.
This is the XML layout for the GridView.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/templatelandscape"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<GridView
android:id="@+id/commandsbarlandscape"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:padding="0dp"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:numColumns="auto_fit"
android:columnWidth="52dp"
android:stretchMode="spacingWidth"
android:gravity="fill_horizontal"
/>
What am I doing wrong ?
© Stack Overflow or respective owner