0
votes

I have to display a splash image which has a round shaped object (a Ball). The Layout for splash is a simple linear layout with just a single Image view to occupy the full screen.

Image : single image with the size of 1280 x 720.

When my splash screen is shown in the App, The round object is shown in different shape in different screen sizes. I hope the aspect ratio and the resolution is the cause for these elongated images.

Could you please suggest an idea / approach to solve this ? Do I need to consider the aspect ratio or the resolution or both ?

Finally the ball should look like a ball in all the devices :)

Thanks in Advance.

3

3 Answers

1
votes

1) Yes, by default Android will scale your image down to fit the ImageView, maintaining the aspect ratio. However, make sure you're setting the image to the ImageView using android:src="..." rather than android:background="...". src= makes it scale the image maintaining aspect ratio, but background= makes it scale and distort the image to make it fit exactly to the size of the ImageView. (You can use a background and a source at the same time though, which can be useful for things like displaying a frame around the main image, using just one ImageView.)

2)You should also see android:adjustViewBounds to make the ImageView resize itself to fit the rescaled image. For example, if you have a rectangular image in what would normally be a square ImageView, adjustViewBounds=true will make it resize the ImageView to be rectangular as well. This then affects how other Views are laid out around the ImageView.

You can change the way it default scales images using the android:scaleType parameter. By the way, the easiest way to discover how this works would simply have been to experiment a bit yourself! Just remember to look at the layouts in the emulator itself (or an actual phone) as the preview in Eclipse is usually wrong.

Reference : How to scale an Image in ImageView to keep the aspect ratio

0
votes

set imageView property

scaleType="centerInside"

0
votes

Add scaled versions of the image with the same file name under folders 'res->drawable','res->drawable-ldpi','res->drawable-hdpi' and under xhdpi "http://developer.android.com/guide/practices/screens_support.html#DesigningResources"