GridView的行为并不像它应该的那样.
此 screenshot显示GridView(在横向模式下)向左刷新.
我希望它居中.
此 screenshot显示GridView(在横向模式下)向左刷新.
我希望它居中.
这是GridView的XML布局.
- <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" />
- </LinearLayout>
我究竟做错了什么 ?
解决方法
我不知道你是否解决了你的问题(我希望是的,我也很晚才回答这篇文章!),但这里有一个线索:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/mainLayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center" >
- <GridView
- android:id="@+id/gridview2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_margin="10dp"
- android:columnWidth="90dp"
- android:numColumns="auto_fit"
- android:stretchMode="spacingWidth" >
- </GridView>
- </LinearLayout>
不幸的是,只有在网格上有1个内容时才能工作.也许有人可以改进它!