保证金/填充在XML比例 [英] Margin/Padding in percentage in XML

查看:165
本文介绍了保证金/填充在XML比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的android开发。我想设置保证金和放大器;填充在XML中,不是在DP或像素但在百分比。有没有办法做到这一点?

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?

推荐答案

这是不可能的,但你最好采取屏幕的宽度和高度,如下面在Java code做,

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.

这种方式,您可以设置保证金根据不固定所有的屏幕,屏幕大小,基本上它就像个,但与Java code设置。

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.

这篇关于保证金/填充在XML比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆