Search code examples
androidbuttonandroid-linearlayoutandroid-gridviewoverlapping

Grid view overlapping other views android


I need to have a button, a grid view and a button, arranged vertically. I can see the Button and the GridView but can't see the button declared after the grid view. Why's that? This happens with any view below the grid view declaration.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
        <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal|center_vertical"
        android:layout_marginTop="20dip"
        android:text="Fragment1"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="30dip" />

        <Button 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button1"/>


     <GridView 
          android:id="@+id/gridview"
          android:layout_width="wrap_content" 
          android:layout_height="match_parent"overla
          android:columnWidth="90dp"
          android:numColumns="auto_fit"
          android:verticalSpacing="10dp"
          android:horizontalSpacing="10dp"
          android:stretchMode="columnWidth"
          android:gravity="center"/>                            

            <Button 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button1"/>
</LinearLayout>

Solution

  • As you have taken LinearLayout with vertical orientation, give wrap_content to the height of GridView.

    Now, if you want last button at below to the screen, then include android:layout_weight="1" in GridView.