[英]Is it possible to add more than one TableLayout in a LinearLayout with a ScrollView in Android development?
[英]TableLayout in Android Development
我在TableLayout中遇到問題,寬度問題。 我嘗試了很多搜索,但是得到的只是使用xml的解決方案。 我正在以編程方式進行操作。 這是我在做什么
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableLayout table = new TableLayout(this);
table.setStretchAllColumns(true);
table.setShrinkAllColumns(true);
TableRow tableTitle = new TableRow(this);
tableTitle.setGravity(Gravity.CENTER_HORIZONTAL);
TableRow name = new TableRow(this);
TableRow password = new TableRow(this);
TableRow button = new TableRow(this);
TextView empty = new TextView(this);
TextView title = new TextView(this);
title.setText("Hello table layout");
title.setGravity(Gravity.CENTER_HORIZONTAL);
TextView txtUname = new TextView(this);
txtUname.setText("Username");
TextView txtPass = new TextView(this);
txtPass.setText("Password");
EditText uname = new EditText(this);
EditText pass = new EditText(this);
Button login = new Button(this);
login.setText("Login");
name.addView(txtUname);
name.addView(uname);
password.addView(txtPass);
password.addView(pass);
button.addView(empty);
button.addView(login);
table.addView(name);
table.addView(password);
table.addView(button);
table.setColumnShrinkable(0, true);
setContentView(table);
}
我想縮小第一列。 我應該在此代碼中添加什么?
有人幫忙!
您應該考慮將其移至布局xml文件。 這會使您的生活更輕松。
要僅使第一列可收縮,請將setShrinkAllColumns(true)
替換為setColumnShrinkable(0, true)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.