我只是创建了一个带有工具栏和 GridView 的简单 xml 文件,问题是 GridView 显示的工具栏信息不在工具栏下方,就像这样 Grid View
这是我的xml文件
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="abtech.waiteriano.com.waitrer.MenuActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<GridView
android:id="@+id/menuGridView"
android:layout_width="match_parent"
android:background="#d2d2d2"
android:layout_height="fill_parent"
android:layout_margin="4dp"
android:columnWidth="80dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="3"
android:stretchMode="columnWidth"
android:layout_below="@+id/toolbar" />
</FrameLayout>
最佳答案
你有不同的选择
将 FrameLayout 更改为 LinearLayout(垂直方向)
将 FrameLayout 更改为 RelativeLayout 并使用“layout_below”
我推荐你使用LinearLayout
例子:
线性布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="abtech.waiteriano.com.waitrer.MenuActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<GridView
android:id="@+id/menuGridView"
android:layout_width="match_parent"
android:background="#d2d2d2"
android:layout_height="fill_parent"
android:layout_margin="4dp"
android:columnWidth="80dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="3"
android:stretchMode="columnWidth" />
</LinearLayout>
相对布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="abtech.waiteriano.com.waitrer.MenuActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<GridView
android:id="@+id/menuGridView"
android:layout_width="match_parent"
android:background="#d2d2d2"
android:layout_height="fill_parent"
android:layout_margin="4dp"
android:columnWidth="80dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="3"
android:stretchMode="columnWidth"
android:layout_below="@id/toolbar" />
</RelativeLayout>
关于java - GridView 显示在工具栏前面而不是下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42533019/