<GridView
android:id="@+id/gridView1"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginRight="100dp"
android:layout_marginLeft="100dp"
android:layout_marginBottom="20dp"
android:numColumns="4" />
因为GirdView中子元素默认的为居左显示
所以使用gravity将GirdView中子元素水平居中显示即可
然后再使用layout_centerInParent将GirdView组件在父容器中居中显示