是否可以以编程方式设置 LinearLayout 的边距,但不能使用像素,而是使用 dp?
您可以使用显示指标 http://developer.android.com/intl/de/reference/android/util/DisplayMetrics.html并确定屏幕密度。像这样的事情:
int dpValue = 5; // margin in dips
float d = context.getResources().getDisplayMetrics().density;
int margin = (int)(dpValue * d); // margin in pixels
我记得最好使用地板进行偏移并舍入宽度。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)