我需要以某種方式來做到這一點之間在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