问题描述
这是一个上,我发现没有答案很简单的问题:/我怎样才能快速进入屏幕分辨率(宽,高)作为整数值?
this is a really simple question on which I've found no answer :/How can I quickly access the screen resolution (width, height) as integer values?
我已经试过这一个,但它总是在我的模拟器显示零:
I've tried this one, but it always shows zero on my emulator:
DisplayMetrics dm = new DisplayMetrics();
int width = dm.widthPixels / 2;
在我来说,我想动态创建一个表tableRows,每块包含两个COLS。这COLS都应当填写半个屏幕的宽度。
In my case I want to dynamically create a table with tableRows, each containing two cols. This cols all shall fill half of the screen in width.
有人可以给我一个提示?
Can someone give me a hint?
推荐答案
最简单的方法将是实施 onSizeChanged 。你可能会得到一个0值,因为该观点尚未初始化。你不能拨打以上code在例如查看构造。
The easiest way will be to implement onSizeChanged. You are probably getting a value of 0 because the view hasn't initialized yet. You can't call the above code in the View constructor for example.
这篇关于安卓:获取屏幕分辨率/像素的整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!