Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make layout_height and layout_width with equal size

I have some image that have resolution 320x320.

For the layout_width it set the value fill_parent

but I do not know what should I set for the layout_height

I want to have equal size for height and width.

If I set layout_height=wrap_content the width is twice bigger then the height...

How can I tall some layout to fill all the space in x but to have y size just as the size of x

like image 286
Lukap Avatar asked Jul 02 '12 09:07

Lukap


1 Answers

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

int width = metrics.widthPixels;

now set the height dynamically using width.

this is the width of the device screen, as you are using layout_width = fill parent.

like image 52
Archie.bpgc Avatar answered Oct 11 '22 16:10

Archie.bpgc