此代码用于显示contentview的宽度和高度,代码在onCreate()方法中调用setContentView()方法之后运行,但它的结果宽度为零和零高度。但是,contentview在屏幕上打开,并且对于宽度或高度都不为0。这里出现了什么问题,以及如何显示contentview的宽度和高度?contentView返回0的宽度和高度
contentview对象不是null,我使用了toString()语句来检查。
如果这不好,那么有没有更好的方式来获得像素的contentView的高度和宽度?
ViewGroup contentViewObj;
View v;
...
@Override
public void onContentChanged() {
// TODO Auto-generated method stub
super.onContentChanged();
//v = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);
v = (View) getWindow().getDecorView().findViewById(android.R.id.content);
Toast.makeText(MainActivity.this, "width of contentview " + v.getWidth()
+ " " + "height of contentView " + v.getHeight(), Toast.LENGTH_SHORT).show();
}