views:

480

answers:

1

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 ?

A: 
  1. android:layout_height="wrap_content" has no meaning for widgets that have their own scrolling, like GridView.

  2. android:layout_alignParentTop="true" and android:layout_centerInParent="true" are for RelativeLayout, not LinearLayout.

Get rid of your android:layout_weight="1.0", change your android:layout_height to "fill_parent" or a specific height, change the LinearLayout to a RelativeLayout, and you may be in better shape.

CommonsWare
It is still not working even with your recommendations.
Jacques René Mesrine