Tiled drawable sometimes stretches

前端 未结 8 619
余生分开走
余生分开走 2020-11-29 20:59

I have a ListView whose items have a tiled background. To accomplish this, I use the following drawable xml:



        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 21:27

    There is a lot of noise about this topic online, with various (and numerous) suggested solutions.

    • If you're still at a loss, my suggestion is to keep all tiled bitmap resources to square, base-2 dimensions.

    ie: 16px by 16px for an xhdpi tile asset.

    I hoped that the Android platform would "over-tile" to fill a space if the bitmap did not tessellate perfectly - and then trim the waste. However trialling a 10px*10px tiled bitmap across mdpi, hdpi and xhdpi (and v2.3 to v4.0)'inconsistently' showed this stretching.

    The base-2 dimension allows for whole and even division as you progress through the various resolutions and as each device tries to paint the tiles each time the view is created.

    In Android development, we contest with the ranging hardware and the vendors dipping their fingers into the platform - sometimes this sort of trivial black magic just works.

    This appears to have resolved the issue for me at least. Worth a shot.

提交回复
热议问题