Android 如何将线性布局与屏幕中心的gridview对齐?

Android 如何将线性布局与屏幕中心的gridview对齐?,android,Android,我在linearLayout中有一个gridView,我想将它对齐在下面屏幕的中心。代码没有给出中心对齐,这里是屏幕短。我希望在屏幕中间有完整的GRIDVIEW。 布局XML: 提前感谢。用下面的代码替换您的代码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height

我在linearLayout中有一个gridView,我想将它对齐在下面屏幕的中心。代码没有给出中心对齐,这里是屏幕短。我希望在屏幕中间有完整的GRIDVIEW。

布局XML:


提前感谢。

用下面的代码替换您的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:background="#000000" >

    <GridView
        android:id="@+id/grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:numColumns="3" />

</RelativeLayout>
试试这个

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:background="#000000">

  <LinearLayout 
android:layout_width="wrap_content"
android:layout_height="match_parent"
  android:gravity="center"
      android:layout_gravity="center_horizontal"
android:background="@drawable/bg"  android:orientation="vertical"
  android:layout_centerInParent="true"  >

<GridView
     android:numColumns="3"
     android:gravity="center"
      android:layout_gravity="center_horizontal"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:id="@+id/grid"

         />



     </LinearLayout>
         </RelativeLayout>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/ic_launcher"  
    android:weightSum="1">

    <GridView
        android:numColumns="3"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/grid"
        android:layout_gravity="center_vertical" />
</LinearLayout>
试试这个

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:background="#000000">

  <LinearLayout 
android:layout_width="wrap_content"
android:layout_height="match_parent"
  android:gravity="center"
      android:layout_gravity="center_horizontal"
android:background="@drawable/bg"  android:orientation="vertical"
  android:layout_centerInParent="true"  >

<GridView
     android:numColumns="3"
     android:gravity="center"
      android:layout_gravity="center_horizontal"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:id="@+id/grid"

         />



     </LinearLayout>
         </RelativeLayout>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/ic_launcher"  
    android:weightSum="1">

    <GridView
        android:numColumns="3"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/grid"
        android:layout_gravity="center_vertical" />
</LinearLayout>

将android:gravity=center放入谢谢你的回答。我把它放在中心,但我想利用下面的空间,这是浪费。我得到这样的输出