Positioning images to fit all size screens - java

I'm having a problem with positioning images,I need to position a lot images over another larger background image.
An image Like this
I have tried Absolute but it does not keep the position of the image say I wanted to put a clip art image of a board pin over the background image and need it pointing at a sun and when it's clicked I get a popup dialog,
but then when I change the size of the emulator screen the clip art image is not at the same position I wanted it on the background image.
I first tried just putting the clip art on it with a image editor and used onTouch Listener but that didn't work out when I changed the size of the screen with the x and y coordinates. And tried Absolute Layout and that doesn seem to keep the position.
any ideas would help me big time thanks

AbsoluteLayout is deprecated, so it's probably best to use relative layout alongside with dp.

You could use relative layout so you can use layout_below="#id/view1", android:layout_toRightOf="#id/view2", and android:layout_toLeftOf="#id/view3". You can also use android:layout_marginLeft="10dip", android:layout_marginRight="10dip", android:layout_marginTop="10dip", and android:layout_marginBottom="10dip" to move the views left/right and up/down relative to their current positions. There is also ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT, ALIGN_PARENT_TOP, and ALIGN_PARENT_BOTTOM. Click here for more properties.

You can manually calculate visible width and height of the image by using its drawable's getIntrinsicHeight() and getIntrinsicWidth() and then set Image's scaleType to FIT_XY (this saves image's ratio, and also makes its size correct, while FIT_CENTER does not).

Related

Android image button scaling / dimensions

Currently in the process of assigning images to the main menu to make it more aesthetic, however when assigning images to buttons how do we know what the correct resolution , aspect ratio or dpi is
For the background I know we can use 9 patch images, or provide the various dpi sizes. For an image button, what would be considered the best bet
Thank you
Covert your images accordingly into hpdi, xhdpi, xxhdpi, xxxhdpi using image resizer and put them in all drawable folders. and for image buttons to set icons use src attribute so icons will be set properly in center.

Is it possible to change an images size independent from an imageview's size?

Is it possible to change an imageview's size after initializing but keep the size the image has after initiliazing? Or is there maybe a way to change an image's size without changing the imageview.
Edit: I need to be able to crop the image from bottom to top without affecting the size of the imageview, so that the bottom part of the image is cut off.
You mist likely looking for android:scaleType of ImageView. See docs.

LIBGDX drawables on devices with different densities/resolutions

I'm new to LIBGDX game development, and I have faced my first problem. I've created 9.patch drawables (buttons) using texture packer. This drawables can be used on low density and also extra high density screens and quality is the same.
If I run my project with that drawable on desktop project the image shown is okay and perfect size. If I run project on low density android device, drawable becomes huge (almost half of the screen). And also If I run project on extra high density android device the button becomes really small.
So my question is, how to handle drawables in LIBGDX, so the ratio (screen:image size), stays the same no matter resolution/density..?
If your button is a text button. Change the font of your text.
If you are using image button, this might help you
It kind of depends on what you're drawing...If you are just drawing an image, I've found it easier to specify a float width and height in the last 2 parameters of the draw method. If you are using a camera with a fixed viewport size, you can simply use a fixed percentage of your camera viewport so it will always be the same dimensions and draw like this:
batch.draw(drawable,x,y,screenwidth * 0.5f,screenheight*0.5f);
However, if you are using buttons or some other widget inside of a table, you should specify the cell size and it should automatically be resized based on the size of the table cell. Something like:
myTable.add(myWidget).width(300).height(200);
Post up exactly what it is that you need to draw if you get a chance and it will be easier to figure out what needs to happen.

How do I keep my splash screen's background from stretching?

How do I go about setting the background for a splash screen that does not stretch, and maintains a density-independent size? Here's a visual of what I'm trying to go for:
I have a large image file (1000x1000px) of the background. I want the background to maintain its density-independent size, with the excess just not visible, so that it will be displayed correctly on various screen sizes. I also want the center of the image anchored to the center of the screen. (the image above is just a mockup, the focal point should be at the center of the image)
How do I do this?
You have a link here in stackoverflow that might help.
You can use an ImageView as your background (otherwise backgrounds of any view will just stretch).
And use it as the background of your ImageView. Your ImageView can then have the layout_width and the layout_height as wrap_content.
Then, set the ScaleType as android:scaleType="centerCrop".
Note that this ImageView has to be the first element of your layout. Otherwise it will just hide everything in your layout.

TextView dp does not scale with screen size

I am attempting to create a textView that will take up a large portion of the top center part of the screen. Ideally, setting the text size in dp would allow the textView to remain the correct relative size (taking up about 70% of the width of the screen, and maybe 20% of the top). It looks correct in the layout editor, and in the emulator at HVGA resolution. However, when I test it at higher resolutions (on my tablet, or emulating a 720p display) the text takes up a very small portion of the top center part of the screen. (maybe 30% width instead of 70%, and it doesn't seem any larger vertically).
Is there a way to scale text to correctly increase relative size with resolution?
Set the layout_width as fill_parent, which will make it spread across the screen for all devices.
Add some padding on left right and top which seems suitable.
The padding might seem different for different screens but still this might be a better solution.
set
android:layout_width="match_parent"
edit:
check this out
Auto Scale TextView Text to Fit within Bounds

Categories