Hovo
Hovo

Reputation: 790

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 https://github.com/intuit/sdp 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?

Upvotes: 1

Views: 323

Answers (2)

Andranik Khandanyan
Andranik Khandanyan

Reputation: 11

Your solution seems good, just as common solution, would be good to use folders described in documentation. For your case, as easier solution I would suggest to not use an apple image separately and place it in background's square. You can have an image: apple in square, and place it on background wherever you want. An apple will always be in a square and you can avoid tiresome process of creating dimens for each configuration.

Upvotes: 1

Royi Benyossef
Royi Benyossef

Reputation: 759

This is indeed the recommended solution as you could see in the iosched github repository which is a generally good source of knowing whether something is a desired common practice at least according to Google since i know they spend a lot of time to create this code to reflect the best practices and obtain the new APIs

Upvotes: 1

Related Questions