4

我正在使用选择器为我的视图设置动画,其中一个我正在这样做:

  • 看法:

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1"
        android:background="@drawable/selector_gridview" >
    
  • 选择器网格视图:

    <?xml version="1.0" encoding="UTF-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item
            android:state_pressed="false"
            android:drawable="@drawable/selector_gridview_normal" 
        />
    
        <item 
            android:state_pressed="true"
            android:drawable="@drawable/selector_gridview_pressed" 
        />
    
    </selector>
    
  • 选择器_gridview_pressed:

    <?xml version="1.0" encoding="UTF-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item>
            <shape>
                <solid android:color="@color/overlayed" />
    
                <stroke 
                    android:width="1px"
                    android:color="#cccac3" />
            </shape>
        </item>
    
         <item>
            <bitmap
                android:antialias="true"
                android:dither="true"
                android:src="@drawable/bg_stripes_dark"
                android:tileMode="repeat" />
        </item>
    
    </layer-list>
    
  • bg_stripes_dark 是一个位于drawable-nodpi文件夹中的 .png。

和 的位图是相同的selector_gridview_normalselector_gridview_pressed但是当按下视图时,位图不会像没有按下视图时那样重复。

MDPI / API 8 device在 4.0 设备(等等)中使用 , 这个问题不存在。

这似乎是 Support v4 Gridview 的问题。实际上它似乎有很多问题。有没有办法解决这个问题?

4

2 回答 2

4

这是我们在 Android 3.0+ 中修复的一个不幸的错误(我不记得确切的版本。)解决此错误的一种方法是BitmapDrawable在加载后获取对它的引用并手动设置磁贴使用setTileModeXY()从代码中重复的模式。

于 2013-07-01T22:32:15.113 回答
0

希望这对你有帮助-

//反向重复normal.xml

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/selector_gridview_normal" 
    android:tileMode="repeat" />

// backrepeatpressed.xml

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/selector_gridview_pressed" 
    android:tileMode="repeat" />

//选择器_gridview.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:state_pressed="false"
        android:drawable="@drawable/backrepeatnormal" 
    />

    <item 
        android:state_pressed="true"
        android:drawable="@drawable/backrepeatpressed" 
    />

</selector>

//布局文件

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="1"
    android:background="@drawable/selector_gridview" >
于 2013-06-27T13:05:50.013 回答