Proportionnal RelativeLayout - android

I want to achieve the following:
a picture, as a background, which resize according to the screen size
I want to put button on top of this picture, while maintaining a proportional position to the picture width and height.
See the example:
The background is an image with the fill_parent settings for width/height.The yellow squares are buttons on top of this picture.
So, how can I keep the button on the exact same position on top of the picture with different screen size, using relative layout (or others layout)

The solution was to use the "Percent Support Library" as stated by #subhash

Related

Pictures in landscape mode on 1920x1200 tablets appear pressed

I want to place a picture in an app on tablet, with resolution 1920x1200 and the picture is the exact same size, but the problem is the software buttons on the bottom have some height and make the picture pressed on the top and bottom sides... How can I know whats the height of the software buttons, and do I have to manually cut every picture, or can I make it programatically?
Or even better, can I just make somehow the picture take the whole screen, and the bottom end ot just go behind the software buttons?
You can try using this if you want to crop the overflowed part -
android:scaleType="centerCrop"
Or alternatively, you can use this if you want to stretch your image to fit the ImageView -
android:scaleType="fitXY"
Also if you want to Fit image into imageview, keeping the aspect ratio and then resize imageview to image, check this - Click Here

Scale down ImageButton / ImageView without leaving space around

I have some problems resizing ImageViews and ImageButtons.
Let's say that I have a Layout that has a rectangular shape (I don't want to know if it is a horizontal or vertical rectangle) and a ImageButton that contains a transparent background and as ImageResource a square image.
I want to keep the button square, so I use setScaleType(ScaleType.FIT_CENTER) to stretch the button. It works well.
The problems come when the button needs to be REDUCED to fit the rectangular layout, instead of stretched: in that case, the image is reduced correctly, but the space reserved in the layout is the one that would be reserved by the image if I hade made it crop.
This is what I think that happens:
the image is put in the layout
the space in the layout is reserved
AFTER THIS the image is resized
if the space asked is increased, the layout is enlarged, otherwise nothing is done
as a consequence in the layout the image results rounded by A LOT of empty space if the image needed to be reduced.
The classical problem is: I have a layout that should contain one row with - say - six square buttons. IF the button size is larger than the height of the Horizontal LinearLayout, the buttons end to be distantiated with a lot of empty space, instead of touching them.
I tried using fixed sizes for the images, to force them resize before putting them in the layout, but this is not a solution for me. First of all I want it to be dynamic (ie: the layout could change size during the app lifetime and the images should follow that). Second of all, when I put the image into the layout it can easily happen that the layout is not set yet and its size returns zero.
Can anyone help me?
Thank you.
Just add the attribute
android:adjustViewBounds="true"
to your image view element in your layout. You can have a look to the post Unwanted padding around an ImageView

Specifying imageView to resize as percentage of screen

In Android I need to have a simple layout to be designed using XML layout (rather than programming):
I need to have the following :
1- small image view on the left (centered vertically)
2- Three image views a bit larger beside each others (also centered vertically)
3- Small image view on the right side (centered vertically)
so the 5 images are adjacent horizontally and centered vertically.
This is simple, anyhow the question is how to specify the image views to resize as percentage of the screen height ?
So if I specify the three image items to be 60% of screen height, I expect the imageView to resize (including the source image) to be 60% of screen height.
Is it achievable?
Thanks
Yes, it is, Take a LinearLayout(Horizontal) and then to all the childs(Imageviews here) give layout:height="0dp" and layout:weight=".6" , try this first and update questions if you have any further

Custom button sizes in pixels

At last i finished my work and now i need to hand it to designer. App has some buttons and checkboxes.
So the question how big button and checkbox should she draw for each screen size(ldpi,mdpi,hdpi,xhdpi) or she could draw just one image for button and anotherone for checbox and it could be scaled?
Thank you already.
It really depends on how big your buttons are. U can check the following link for sizes:
http://developer.android.com/images/screens_support/screens-densities.png
But I agree with Mikelsreal (create a 9 patch image).
Create the button image in whatever size u like.
Add black pixels above the image to set where the image should be stretch horizontal.
Add black pixels on the left side of the image to set where the image should be stretch vertical.
Add black pixels on the right side where the content can be placed vertical
Add black pixels below the image to set where the content can be placen horizontal
rename the image like : yourImageName.9.png
and it should work.
for more info check (developer.android.com/tools/help/draw9patch.html)

Android: Stretching ImageView with background

I have a landscape layout that features a vertical LinearLayout of buttons on the left side of the screen and a user-defined picture on the right of the screen. The design I'm working from calls for a double-stroke border around it, which I implemented by creating a rectangular shape background with the border being the outer color and the background of the shape being the inner color. I then just put some padding around the picture, and you get the double-stroke border. The problem is expanding the picture to fill the space in the layout. I don't know the dimensions of the picture, since it is user defined, and I'd like it to expand to exactly fill either dimension while preserving the aspect ratio. Setting fill_parent for both width and height does that, but it also expands the background all the way to completely fill the cell, resulting in a sort of letter boxing effect. Is there any way, short of just adjusting the size of the view after layout, of getting this to only expand the view as much as necessary?
I never got this to work properly, and just ended up adjusting my layout to a different arrangement.

Categories

Resources