문제

I've got a basic GridView that I've set up as follows:

<?xml version="1.0" encoding="utf-8"?>
    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/MainMenuGridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:numColumns="auto_fit"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:columnWidth="90dp"
        android:stretchMode="columnWidth"
        android:gravity="center"
    />

Everything works fine until I add a ninepatch background. Once I add the background image like this:

 <?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MainMenuGridview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:numColumns="auto_fit"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:columnWidth="90dp"
    android:stretchMode="columnWidth"
    android:gravity="center"
    android:background="@drawable/mainbackground"
/>

It breaks my gridview. Instead of displaying 3-4 columns (depending on screen resolution and orientation) all icons in the gridview display in a single column in the upper left corner. Furthermore, only two at a time are displayed and I have to scroll down to see the rest. I suspect that the gridview is being bound by the dimensions of the ninpatch's center logo, but I'm not sure.

My ninepatch has a small area in the middle with a logo that I want to be displayed without any skewing. The rest of the background is a small gradient that takes up the remainder of the screen. Any ideas on what's causing this?

도움이 되었습니까?

해결책

Sounds like you have padding defined (the lines at the bottom and right of the ninepatch)? Try getting rid of those, so you only have content area defined (the lines at the top and left)

다른 팁

I had a similar problem. Unfortunately I want to use padding in my case. What I found is that the order of method calls on gridLayout seem to make a difference. As long as I called setPadding() after setBackgroundResource(), all is fine.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top