2011-09-28 16 views
17

Mam problemy, w których mój zasób do rysowania używa powtórzenia tileMode. W niektórych przypadkach obraz jest po prostu rozciągnięty, a czasami jest poprawnie powtórzony.Błąd XML tileable Bitmap tileMode?

są następujące pliki xml używam do tworzenia przycisków stany: rozciągliwej

obraz używany płytki wielokrotne

Image drawable used for tile repeated

^^^^^^^^^ ^^^^

btn_menu_item.xml

<selector 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:constantSize="true" android:visible="true" android:variablePadding="true"> 
    <!-- selected --> 
    <item 
     android:state_selected="true" 
     android:drawable="@drawable/menu_item_selected"/> 

    <!-- focused --> 
    <item 
     android:state_focused="true" 
     android:drawable="@drawable/menu_item_pressed"/> 

    <!-- pressed --> 
    <item 
     android:state_pressed="true" 
     android:drawable="@drawable/menu_item_pressed"/> 

    <!-- normal --> 
    <item 
     android:state_pressed="false" 
     android:state_focused="false" 
     android:drawable="@drawable/menu_item_normal"/> 

</selector> 

menu_item_normal.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_selected="true"> 
     <shape android:shape="rectangle"> 
      <gradient 
       android:startColor="#757575" 
       android:endColor="#929292" 
       android:angle="90"/> 
     </shape>  
    </item> 

    <item> 
     <bitmap 
      android:src="@drawable/menu_lines_texture" 
      android:tileMode="repeat" 
      android:dither="true"/> 
    </item> 
</layer-list> 

menu_item_pressed.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_selected="true"> 
     <shape android:shape="rectangle"> 
      <gradient 
       android:startColor="#dd4e00" 
       android:endColor="#c64600" 
       android:angle="90"/> 
     </shape> 
    </item> 

    <item> 
     <bitmap 
      android:src="@drawable/menu_lines_texture" 
      android:tileMode="repeat" 
      android:dither="true"/> 
    </item> 
</layer-list> 

proszę zobaczyć obrazy poniżej tego, co dokładnie mówię.

Normal state image properly repeated Pressed state image not repeated but stretched

Odpowiedz

22

Ten znany błąd częściowo rozwiązany w Androida 3.0 i całkowicie ustalone w segmencie ICS.

+0

Dzięki za odpowiedzi na ten temat! Czy istnieje obejście tego problemu? – Jona

+8

Ustaw tryb kafelkowy z kodu. –

+0

Ciągle znajduję ten problem w 3.2 na Xoom. Ustawienie w kodzie naprawia to. –

2

Podobny problem dotyczy wersji 3.2 na urządzeniu Google TV firmy Sony. Zauważyliśmy bardzo podobne tło-paski wynikające z użycia android:tileMode="repeat" w bitmapie jako obrazu tła.

W tym przypadku, fix było wyłączyć akcelerację sprzętową na widoku, który zawierał bitmapę jak tak (z funkcją w naszej działalności):

View tile_holder = this.findViewById(R.id.tile_holder); 
tile_holder.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
+0

Mogę za to ręczyć. Problem nadal występuje na starszych telefonach z Lollipopem, ustawienie trybu kafelkowego programowo nie działało, ale stało się tak (poprzez plik układu zawierającego). – batterj2