我有一个视图由tablelayout、tablrows和textviews组成。看起来像一个网格。我需要得到这个网格的高度和宽度。当我动态的格式化网格或使用xml版本时,方法getheight() and getwidth()总是返回0。
谁能告诉我如何检索一个试图的尺寸规模?
以下是我在Debug的测试程序:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TextView;
public class appwig extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maindemo);
int vh = 0;
int vw = 0;
TableLayout tl = (TableLayout) findViewById(R.id.board);
tl = (TableLayout) findViewById(R.id.board);
vh = tl.getHeight();
vw = tl.getWidth();
TextView tv = new TextView(this);
tv.setHeight(20);
tv.setWidth(20);
vh = tv.getHeight();
vw = tv.getWidth();
}
}