如何设置 table 的小标题行的宽度?
how to set width of tittle row of a table?
TableLayout tl = new TableLayout(ActivityAddFlashcard.this);
TableRow tittleRow = new TableRow(ActivityAddFlashcard.this);
TableRow fRow = new TableRow(ActivityAddFlashcard.this);
TableRow.LayoutParams params = new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT);
fRow.addView(getTextView("کلمه"));
fRow.addView(getTextView("معنی"));
TextView tv = new TextView(ActivityAddFlashcard.this);
tv.setLayoutParams(new TableRow.LayoutParams(tl.getWidth() // <---- //return 0
, TableRow.LayoutParams.WRAP_CONTENT));
tv.setText("dksvlfsnfmmmmnv");
tittleRow.addView(tv);
tittleRow.setGravity(Gravity.CENTER);
tl.addView(tittleRow);
fRow.addView(new TextView(ActivityAddFlashcard.this));
tl.addView(fRow);
TableLayout.LayoutParams params2 = new TableLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT);
fRow.setGravity(Gravity.CENTER);
fRow.setLayoutParams(params);
tl.setLayoutParams(params2);
tl.setGravity(Gravity.CENTER);
这是我的 table 布局,我想将标题行的宽度设置为等于 table 的宽度。
但是 getWidth return 0 .
您的视图可以在布局过程中不时更改其宽度。可能您正在寻找 MATCH_PARENT
解决方案:
tv.setLayoutParams(
new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT
)
);
您可能也有兴趣将 MATCH_PARENT
设置为 tittleRow
的 layoutParameter
。
TableLayout tl = new TableLayout(ActivityAddFlashcard.this);
TableRow tittleRow = new TableRow(ActivityAddFlashcard.this);
TableRow fRow = new TableRow(ActivityAddFlashcard.this);
TableRow.LayoutParams params = new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT);
fRow.addView(getTextView("کلمه"));
fRow.addView(getTextView("معنی"));
TextView tv = new TextView(ActivityAddFlashcard.this);
tv.setLayoutParams(new TableRow.LayoutParams(tl.getWidth() // <---- //return 0
, TableRow.LayoutParams.WRAP_CONTENT));
tv.setText("dksvlfsnfmmmmnv");
tittleRow.addView(tv);
tittleRow.setGravity(Gravity.CENTER);
tl.addView(tittleRow);
fRow.addView(new TextView(ActivityAddFlashcard.this));
tl.addView(fRow);
TableLayout.LayoutParams params2 = new TableLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.WRAP_CONTENT);
fRow.setGravity(Gravity.CENTER);
fRow.setLayoutParams(params);
tl.setLayoutParams(params2);
tl.setGravity(Gravity.CENTER);
这是我的 table 布局,我想将标题行的宽度设置为等于 table 的宽度。 但是 getWidth return 0 .
您的视图可以在布局过程中不时更改其宽度。可能您正在寻找 MATCH_PARENT
解决方案:
tv.setLayoutParams(
new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT
)
);
您可能也有兴趣将 MATCH_PARENT
设置为 tittleRow
的 layoutParameter
。