我有一个观点TableLayout, TableRow and TextView.我希望它看起来像一个网格.我需要得到这个网格的高度和宽度.这些方法getHeight()和getWidth()总是返回0.这发生在我和动态也格式化网格时我使用XML版本.
如何检索视图的尺寸?
这是我在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); //<- includes the grid called "board"
int vh = 0;
int vw = 0;
//Test-1 used the xml layout (which is displayed on the screen):
TableLayout tl = (TableLayout) findViewById(R.id.board);
tl = (TableLayout) findViewById(R.id.board);
vh = tl.getHeight(); //<- getHeight returned 0, Why?
vw = tl.getWidth(); //<- …Run Code Online (Sandbox Code Playgroud)