Android - 结合 GridView 和 LinearLayout

Android - Combine GridView with LinearLayout

对于我的 Activity,我使用的是显示其项目的 GridView。 这是我的 GridView 主要布局:

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:columnWidth="160dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>

然后我当然有每个项目的布局。这是结果:

现在我想在 GridView 下面添加 2 个元素(按钮)。但是,如果我将 LinearLayout 放在 GridView 中,我的应用程序就会崩溃。

如何在 GridView 之后添加带有 2 个按钮的 LinearLayout?

将您的网格视图包含到父亲线性布局中,然后将新的线性布局添加到网格视图下方的父亲线性布局中。如下图

<linearlayou> 
  <gridview></gridview>
  <linearlayour></linearlayout>
</linearlayout>