2011-09-28 39 views
17

Tôi đang gặp sự cố trong đó tài nguyên có thể drawable của tôi sử dụng lặp lại tileMode. Trong một số trường hợp, hình ảnh chỉ được kéo dài và đôi khi nó được lặp lại đúng cách.XMLmap bitmap có thể vẽ đượcMã lỗi?

Sau đây là các tập tin xml tôi sử dụng để tạo ra các trạng thái nút:

ảnh drawable sử dụng cho gạch lặp đi lặp lại

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> 

Hãy xem những hình ảnh dưới đây về những gì chính xác tôi đang nói về.

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

Trả lời

22

Đây là một lỗi được biết, một phần cố định trong Android 3.0 và hoàn toàn cố định trong ICS.

+0

Cảm ơn trả lời của bạn về vấn đề này! Có một cách giải quyết cho điều này? – Jona

+8

Đặt chế độ hình xếp từ mã thay thế. –

+0

Tôi vẫn đang tìm vấn đề này trong 3.2 trên Xoom. Đặt nó trong mã sửa chữa nó. –

2

Chúng tôi đã gặp sự cố tương tự khi viết 3,2 trên thiết bị Google TV của Sony. Chúng tôi nhận thấy một số dải nền rất giống nhau bắt nguồn từ việc sử dụng android:tileMode="repeat" trên bitmap làm hình nền.

Trong trường hợp này, việc sửa chữa là để tắt khả năng tăng tốc phần cứng trên quan điểm cho rằng chứa bitmap như vậy (từ một chức năng trong hoạt động của chúng tôi):

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

Tôi có thể xác minh cho điều này. Sự cố vẫn tồn tại trên các điện thoại cũ chạy Lollipop, việc đặt chế độ ô vuông theo lập trình không hoạt động nhưng điều này đã làm (thông qua tệp bố cục chứa). – batterj2

Các vấn đề liên quan