<GridView android:id="@+id/grid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:verticalSpacing="35px" <!-- grid元素之間的豎直間隔 --> android:horizontalSpacing="5px" <!--grid元素之間的水平間隔 --> android:numColumns="auto_fit" <!--表示有多少列,如果設置爲auto_fit,將根據columnWidth和Spacing來自動計算 --> android:columnWidth="100px" <!-- 一般建議採用有像素密度無關的dip或者dp來表示--> android:stretchMode="columnWidth" <!--如何填滿空餘的位置,模擬器採用WVGA800*480,每排4列,有4*100+5*3=415,還餘65px的空間,如果是columnWidth,則這剩餘的65將分攤給4列,每列增加16/17px。如果採用SpacingWidth,則分攤給3個間隔空隙 --> android:gravity="center" />