在Android和底视图之间居中查看视图

art*_*ros 2 android gridview view

我需要以某种方式这样做:

我尝试使用相对布局,我放置了顶部的imageview和底部按钮但是如何将我的gridview放在中心?但是在顶部图像和底部按钮之间?

ada*_*amp 6

顶部图像和底部按钮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>
Run Code Online (Sandbox Code Playgroud)