Tying images to one another and scaling? - android

I have an application that needs to scale an image in relation to another image due to different screen size, I have an image that is essentially a background that matches the width of the screen and another image in a relative layout that is aligned so it fits on my phone in 2.2 but when seen on 2.1
Or ... i could just use something that scales the image as a percentage. Suggestions?
edit:
I guess all i need is to know how i can keep an image in a spot relative to another using relative layout and scale it through a percentage, different screen size will scale the other image but not this one because the other image fills the parent so when the screen size is smaller it just scales it down, however the one i need to scale does not because it doesn not fill the parent.

Related

Round shaped image is elongated horizontally or vertically

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.
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
set imageView property
scaleType="centerInside"
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"

Android ImageView scaleType

I have an image to be used a background in activity:
I want this image to fit screen by its height.
It means that for wide-screen smartphones, I want my image to be fit by height and centered:
and for square-screen smartphones, I want my image to be cut:
I use ImageView for the image. What scaleType should I use? Looking at the second figure, I'd say to use android:scaleType="centerInside". But looking at the third, I'd say to use android:scaleType="centerCrop". What is correct?
Your evaluation of the different scaleType's is correct. If you want the whole image to be visible, use "centerInside", or if you want to fill the whole view then use centerCrop.
To use a mix of both, you can set the scaleType in your onCreate() method. Based on the behavior you want to have, you can check the orientation or size of the screen and set the appropriate choice.
imageView.setScaleType(ScaleType.CENTER_INSIDE); // or ScaleType.CENTER_CROP
You can have two layouts, one for each of your configurations. You can then load the proper one at the activity's onCreate() call.
When you fit one side of image to background, you will face with two problems, first one is screen width is bigger than image's width or screen height is bigger than image height.So you will have empty space.
If you do not want to face with resolution problem and you want to fit both side of image to background, you need to use centerCROP.But as i said, if one side of image is not enough to fit background, image gets bigger till it will be filled.
Use centerCrop because centerInside doesn't scale an image in a view and you have to create the image with appropriate height to achieve wide-screened smartphones background filling. Or alternative you could use fitCenter to get uniformly scaled image by both axes which fills the all background.

Android: Stretch Widescreen Image to fill the whole screen

I have a Widescreen Image that i want to put into a horizontal scroll view, with it ftting the whole screen vertically(and letting me scroll horizontally) but it simply stays at half height and won't let me scale it higher (layout_height is set to "fill_parent").
I already thought about using the image in different source resolutions but i think i cannot cover all possible resolutions so that is not really an option i guess.
I also want to put buttons on specific locations onto that image and want them to move with the image if that is important.

Android resource that scales on one axis and tiles on another

We're working on the Android version of one of our games and we're having a problem with a background image. On iOS, it's really easy to scale the image down to the appropriate width and configure it to stretch vertically.
However, on Android, we can't figure out a way to do this. Basically, because of the myriad screen sizes and resolutions, we'd like to have our background image (which frames the play area) scale down to fit the width of the screen. Then, the bottom and top portions of the image should have the right aspect ratio but the middle part should tile (or stretch even) to fill the rest of the area.
We tried this with a nine-patch file but nine-patches don't scale down. We've tried it with LayerDrawables which works well except that it won't tile the middle as the size of the layout changes; it just stretches the entire image instead.
Is there any way to get a drawable to scale to fit horizontally and then tile a section to grow vertically?

Android layout, specify dp to scale with screen size

I've been trying to get a universal layout working on Android with no success. My understanding is that if you specify all widgets in dp, and make it look right in one screen size, it should scale properly to other resolutions, but my results look kinda wrong to me.
I layed out everything in HVGA using a relative layout. The relative layout has a background that our UI designer used to define element boundaries. In this layout, everything looks perfect.
Then I switch to a larger screen with a slightly different aspect ratios, the background scales properly but everything else looks off by some dp. My question is, what is the golden way to make all the elements scale correctly with screen. I want to preserve the ratios of all the elements with respect to the background.
Thanks!
Edit: figured out how to do this. The reason for inconsistency between buttons and background is that background is scaled differently from dp, and devices apparently have different dps. The solution is to manually compute the scale factor from absolute pixels then scale everything manually by that factor. Here is a good reference how to do this:
Scale Android for different screens
dp scales itself in such a manner so that the size of any widget remains constant on different screens having different resolution.
In your case, the size of list-view remains constant but the background stretched to the screen width. To avoid this, use first colour as background of first list-view and same as for second list-view.

Categories

Resources