Android: Gridview not showing correctly
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.开发者_Python百科 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:stretchMode
attribute to be none
:
android:stretchMode="none"
in your GridView
declaration.
Setting the GridView's width to "190px
" would also solve this problem (with the defaultSelector's margins being of 5 pixels wide for the GridView
, you need an extra 10px).
Other: you should probably use a ListView
if you have only one column anyway...
Change background color of Gridview android:background="#333" I do not know why is this happening with default it is totally white font and back therefor it is not visible to. I think it is bug in earlier versions.
精彩评论