0

Can anyone suggest me how to take layout height in percentage manner.

I have to design a layout with

  • an image 40 percent height

  • 2 text views with 10 percent height respectively

  • one linear layout with buttons inside of it with 20 percent height

    and finally

  • a button with 10 percent of actual screen height.

Is it possible using xml?

Thanks for answer..

Community
  • 1
  • 1
user3057567
  • 147
  • 2
  • 2
  • 12

1 Answers1

1

Yes, use layout_weight, for doing this set height of all the fields you want to include to 0dp, and then start assigning them heights using weight, like in your case

for Images, weight will be .4 for textview .1 & .1 Buttons, .2 and final button again with .1 as layout weight.

Techfist
  • 4,314
  • 6
  • 22
  • 32
  • Thanks for reply..and have one more doubt can we add width also in percentage manner at the same time? – user3057567 Dec 10 '13 at 09:39
  • yes use the same layout weight methodology, remember whichever attribute you want to control by weight among height/weight set it as 0dp and provide appropriate weight. – Techfist Dec 10 '13 at 09:44
  • Is this the way? – user3057567 Dec 10 '13 at 09:51
  • no no no not this way, see you can either set height or width to zero dp at once and supply value by layout weight, to control other attirbute what you can do is to warp that widget with another layout such as LinearLayout and supply the second attribute as zero and control it via layout weight. – Techfist Dec 10 '13 at 09:53
  • I tried but it's not working..what i did is I took that image view in relative layout ..so it is giving me warning as invalid layout parameter....what I should do now? – user3057567 Dec 10 '13 at 10:04
  • @user3057567: post code – Mehul Joisar Dec 10 '13 at 10:05
  • Awesome, please accept this as answer then – Techfist Dec 11 '13 at 06:10