mardi 31 mars 2015

Android layouts - images for the different screen resolutions and the same density

I want to show some images on the background that is also image. Say my background image contains an empty squares, and I want to show an apple image that must appear exactly in one of that squares. I have a problems with the apple sizes, as the background scales and fits the screen, but apple image stays the same for the different resolution and the same density devices.


Say I have two ldpi devices with 240x320 and 480x800 resolutions. When I keep my drawable aple file in the drawable-ldpi folder, and use wrap_content for height and width (or fixed dp values) those 2 devices draw the apple with the same size, like it is described in the documentation.


The LinearLayout works slow when I stack them. Using RelaytiveLayout I must programmatically resize the images which is also "not so good" solution I guess.


I've found a solution here http://ift.tt/1NpJWzr that maps the dp-s.


They set dimen-s for values-sw300dp to be



<dimen name="_10sdp">10.00dp</dimen>


and for values-sw480dp to be



<dimen name="_10sdp">16.00dp</dimen>


and so on for the different cases ...


So when I set the with of the apple to be _10sdp it means different dp-s for my 2 devices with the same density and solves my problem. Is it a good solution as it seems to be for me? Is there any other easy ways?


Aucun commentaire:

Enregistrer un commentaire