I’m trying to build a screen with a single column grid that is 180px wide and attaches to the right side of the screen. The problem I’m facing is that the background of the gridview paints the whole screen and not just that 180px I specified in the XML (thus blocking my background pic specified in the LinearLayout).
Neither using weight nor gravity solves the problem.
Seems simple enough yet I’ve been toying with this for hours to no avail. Thanks in advance for your help.
My layout.xml as follows:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/main_bkgd">
<GridView
android:layout_height="fill_parent"
android:scrollbars="none"
android:numColumns="1"
android:columnWidth="180px"
android:verticalSpacing="6dp"
android:layout_width="wrap_content"
android:id="@+id/mainmenu_grid"
android:gravity="right"
android:fadingEdge="vertical"
android:layout_gravity="right"
android:background="#000000"
android:layout_weight=".35">
</GridView>
</LinearLayout>
You should specify the
android:stretchModeattribute to benone:in your
GridViewdeclaration.Setting the GridView’s width to “
190px” would also solve this problem (with the defaultSelector’s margins being of 5 pixels wide for theGridView, you need an extra 10px).Other: you should probably use a
ListViewif you have only one column anyway…