我有以下代码:
public OuterClass extends Activity {
protected int width;
protected int height;
public void onCreate(....){
t1.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight,
int oldBottom) {
UIThroughCode.this.width = right - left;
UIThroughCode.this.height = bottom - top;
}
}
int newwidth = (int) (42 + (12.5 - (width / 2)));
int newheight = (int) (18 + (12.5 - (height / 2)));
我将类顶部的宽度和高度声明为全局变量,我在addLayoutChangeListener方法中更改这些变量的值。但是,当我尝试在上面两个语句中使用更改的值时,为了计算新的宽度和高度,width和height的值为零,这意味着addLayoutChangeListener方法没有更改它们。
您能否帮我从addLayoutChangeListener方法访问更改的宽度和高度值?