Repeating a bitmap does not reflect well in the state_pressed view

I use a selector to animate my views, and in one of them I do like this:

  • View:

    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="1" android:background="@drawable/selector_gridview" > 
  • 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> 
  • 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 is a .png located in the drawable-nodpi .

The bitmap is the same for selector_gridview_normal and selector_gridview_pressed , but when you click on the view, the bitmap does not repeat as if it had not been clicked.

I am using MDPI / API 8 device , in 4.0 devices (and therefore) this problem does not exist.

This seems like a problem with v4 Gridview support. In fact, he has a lot of problems. Is there any way to solve this?

+4
source share
2 answers

This is an unsuccessful error that we are fixing in Android 3.0+ (I don’t remember which version). One way to get around this error is to get a link to BitmapDrawable after you have downloaded it and manually set the tile mode to repeat from the code using setTileModeXY () .

+4
source

Hope this helps you -

// backrepeatnormal.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" /> 

// selector_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> 

// layout file

 <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="1" android:background="@drawable/selector_gridview" > 
0
source

Source: https://habr.com/ru/post/1486936/


All Articles