Search code examples
androidandroid-layoutandroid-linearlayoutandroid-gridview

Android - Combine GridView with LinearLayout


For my Activity I'm using a GridView which displays its items. This is my main-layout for the 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>

Then I have of course the layout for each item. This is the result:

enter image description here

Now I want to add 2 elements (Buttons) below the GridView. But if I put a LinearLayout inside the GridView my App is crashing.

How can I add a LinearLayout with 2 Buttons after the GridView?


Solution

  • include your grid view into a father linearlayout then add the new linear layout to the fathe linear layout below the gridview. like below

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