tags:

views:

36

answers:

1

I'm trying to display an image above and below a grid. This is the initial screen with Logo on top, 4 buttons as a grid view then image on the bottom. With my current code the bottom image is not displaying at all. Also I would like to stick the bottom image "bottomboxes" to the bottom of the display.

<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingTop="20dp"
android:src="@drawable/stuffbox" 
android:gravity="center"/>

<GridView 
android:id="@+id/gridview"
android:paddingTop="10dp"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:columnWidth="40dp"
android:numColumns="2"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>

<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/bottomboxes" 
android:paddingTop="20dp"
/>

</LinearLayout>
+2  A: 

Your current layout has the GridView set to fill_parent both directions. This will force the gridview to fill the entire linearlayout and push the other views away.

Instead you should put:

<GridView  
android:id="@+id/gridview" 
android:paddingTop="10dp" 
android:layout_width="fill_parent"  
android:layout_height="0dp" 
android:layout_weight="1" 
android:columnWidth="40dp" 
android:numColumns="2" 
android:verticalSpacing="10dp" 
android:horizontalSpacing="10dp" 
android:stretchMode="columnWidth" 
android:gravity="center"/> 

The lines android:layout_height="0" and android:layout_weight="1" tell the gridview to fill the remaining available space in the layout, while still allowing the imageviews to have their place.

CodeFusionMobile
this worked great! the only change I made was change android:layout_height="0"to android:layout_height="wrap_content"it won't allow an 0.Thanks again!
bdudaday
@bdudaday Sorry, that should have been 0dp. Using 0dp is still the best way to go. You shouldn't set layout_height to wrap_content on a grid view because it will try to measure it's contents. Setting to zero saves a surprising amount of CPU.
CodeFusionMobile