0

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>
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
Namratha
  • 16,630
  • 27
  • 90
  • 125

3 Answers3

1

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.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • Thanks, it worked!Can't believe I missed the width value :) Could you take a look at this please. I think you might be able to help me. http://stackoverflow.com/questions/14702941/button-width-does-not-match-parent-android – Namratha Feb 05 '13 at 08:22
  • I now have some other views above grid view. When I change the visibility of grid view from 'gone' to 'visible', it interferes with the views above(some of them just disappear). I tried assigning weights to all the views but that doesn't seem to help. – Namratha Feb 06 '13 at 09:05
0

try this

  <RelativeLayout 
   android:layout_width="match_parent"
   android:layout_height="match_parent">
 <Button 
     android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button1"/>

 <Button 
    android:id="@+id/button2"  
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Button1"/>

techieWings
  • 2,045
  • 2
  • 16
  • 18
0

as you have declared height of gridview as match_parent it should overlap the views declared below it if it can not find enough screen space available to show it. You should try calling bringtoFront() method on the view declared below gridview. Other thing from my viewpoint is to try relativeLayout if possible and use android:layout_above and android:layout_below with gridview.

kaushal trivedi
  • 3,405
  • 3
  • 29
  • 47