Himanshu Dudhat Himanshu Dudhat - 1 year ago 100
Android Question

Margin/Padding in percentage in XML

I am new in android development. I want to set margin & padding in Xml,not in dp or px but in percentage. Is there any way to do this?

Answer Source

it is not possible, though You better do it by taking width and height of screen like below in your java code, and

 Display display = getWindowManager().getDefaultDisplay(); 
 int width = display.getWidth();
 int height = display.getHeight();

then calculate your margin from screen size, and set it by

  setmargin(int x) //method of view/layout.

this way you can set margin depending on the screen size not fixed for all screen, and basically it is like setting in percentage but from Java code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download