我有一个水平的线性布局。它有三个文本视图。我如何设置它,使左右宽度都是包装内容,但中心单元格宽度完全最大化,并且文本视图在其中左对齐?我只想用java创建这个。
到目前为止,这就是我所拥有的,但中间的细胞并没有被最大化。。。有人知道怎么解决这个问题吗?感谢
LinearLayout titleLL = new LinearLayout(this);
titleLL.setOrientation(LinearLayout.HORIZONTAL);
TextView num = new TextView(this);
num.setText(String.format("%d", index+1));
num.setPadding(5, 5, 5, 5);
num.setTextAppearance(this, R.style.title_numbering);
num.setBackgroundResource(R.drawable.title_numbering_background);
TextView name = new TextView(this);
name.setText(task.name);
name.setPadding(10, 0, 0, 10);
name.setTextAppearance(this, R.style.title);
TextView edit = new TextView(this);
edit.setText("Edit");
titleLL.addView(num);
titleLL.addView(name);
titleLL.addView(edit);
添加中间文本视图时使用权重:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
0, LinearLayout.LayoutParams.WRAP_CONTENT, 1);
titleLL.addView(name, params);