Sandah Aung
Sandah Aung

Reputation: 6188

Load different resources depending on aspect ratio

My Android app's welcome screen would look like the one shown below.

denko on phone

However, I also need to support tablets which have wider screen. This unfortunately leaves little room for the logo at the bottom of the screen.

denko on tablet

I either need to crop the top and bottom of the background image a little or make the logo smaller if I detect a widescreen device.

How do I know if a device is widescreen? How do I crop images at runtime? Can I ask Android to load an alternative resource depending on screen aspect ratio? Can this be done using xml files without resorting to doing things programmatically?

Upvotes: 1

Views: 369

Answers (2)

akadouri
akadouri

Reputation: 128

You can have different folders like layout-large and layout-medium just like you have drawable-hdpi, drawable-mdpi, etc. This will change which layout file it uses based on the device. For more reading checkout Google's training.

Upvotes: 1

inmyth
inmyth

Reputation: 9070

You can define different layouts depending on screen width: Difference between sw600dp and w600dp?

I think the only thing that should be the background image is the gas pump photo. Text should not be put in image because if the image is rescaled / stretched then the distortion will look horrible. So I would have RelativeLayout as root view, set with that photo. And then I would have two elements "Denko" and "Welcome" which can be TextView and ImageView wrapped in a layout. Then I would set layout_above for "Message" with "Denko"'s id. This way "Message" will always be above "Denko".

Upvotes: 1

Related Questions