【发布时间】:2011-12-08 10:08:34
【问题描述】:
我有一个名为 game 的类,它扩展了添加到 LinearLayout 的 View。我知道它正在显示我的视图,但我需要获取视图的宽度和高度才能绘制我的一些图像。这是我的构造函数代码:
public Game(Activity activ)
{
activ.setContentView(R.layout.game);
...
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
setLayoutParams(lp);
layout = (LinearLayout)activ.findViewById(R.id.game_layout);
layout.addView(this);
...
}
现在,当我执行 this.getWidth() 和 this.getHeight() 时,我的返回值一直为 0。如何获得视图的宽度和高度?
【问题讨论】: