本文翻译自:Android and setting width and height programmatically in dp units
I'm doing: 我正在做:
button.setLayoutParams(new GridView.LayoutParams(65, 65));
According to the docs the units for the width and height (both 65 in the above) are "pixels". 根据文档,宽度和高度的单位(上面均为65)是“像素”。 How do you force this to be device independent pixels, or "dp"? 你如何强制这是设备无关的像素,或“dp”?
#1楼
参考:https://stackoom.com/question/m372/Android并以dp为单位以编程方式设置宽度和高度
#2楼
I k