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_heig开发者_如何学Cht="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>
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.
精彩评论