我需要以某种方式来做到这一点之间在Android上查看:中心底部和顶部视图
我试着用相对布局玩,我把上面的ImageView和底部的按钮,但我怎么把我的GridView在中心?但是,顶部图像和底部按钮之间?
我需要以某种方式来做到这一点之间在Android上查看:中心底部和顶部视图
我试着用相对布局玩,我把上面的ImageView和底部的按钮,但我怎么把我的GridView在中心?但是,顶部图像和底部按钮之间?
有顶部图像和底部的按钮使用wrap_content
的高度,并在GridView使用0dip
身高,重量为1沿着这将导致顶部和底部元件首先进行测量,并且GridView将获得中间的所有剩余空间。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView android:id="@+id/top_image"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<GridView android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<Button android:id="@+id/bottom_button"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
使用这样的事情
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/table">
<TableRow
android:weightSum="100">
<ImageView android:id="@+id/image1"
android:src="@drawable/icon"
android:visibility="visible"
android:gravity="center"
android:layout_weight="50" />
</TableRow>
<TableRow
android:weightSum="100">
<GridView
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</GridView>
</TableRow>
<TableRow
android:weightSum="100">
<Button android:id="@+id/btn1"
android:visibility="visible"
android:gravity="center"
android:layout_weight="50" />
</TableRow>
</TableLayout>
</LinearLayout>
adamp的回答对我无效。这是我发现完美地工作:在最里面的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:id="@+id/top_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<Button android:id="@+id/bottom_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<LinearLayout
android:id="@+id/container_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/bottom_button"
android:layout_below="@id/top_image"
android:gravity="center" >
<GridView android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</RelativeLayout>
我已经与其他LinearLayouts
到位GridView
的用这个,用android:gravity="center"
集,以及使所有的其文本的意见和图像水平居中以及垂直。
你可以试试这个:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView android:id="@+id/top_image"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<GridView android:id="@+id/grid1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<Button android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
这些添加到您的网格视图:
android:layout_above="@id/bottom_button"
android:layout_below="@id/top_image"
我需要的GridView,从而精确匹配顶部和底部的细胞之间的空间。 – artouiros 2011-05-15 16:08:00