获取onCreate()中按钮的大小

时间:2011-05-05 01:09:46

标签: android button

我想获得放在onCreate()上的surfaceView中的按钮的大小。我怎么做到的?

如果我在onCreate()中使用button.getWidth(),我得到0.但是,我可以在onStart()中获得按钮的大小,但这不是预期的。我理解这种行为的原因。

但是,如果我想在我的活动的onCreate()中根据按钮的大小放置另一个视图,我该如何实现?

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我不认为你可以在OnCreate()中获得你的按钮宽度来获得宽度和高度,你可以使用下面的方法

@Override
public void onWindowFocusChanged(boolean hasFocus) {
   super.onWindowFocusChanged(hasFocus);
    // Call here getWidth() and getHeight()
}
相关问题