我有滚动视图和表格布局,行表。
现在我想在编程代码而不是xml中为每个设置X和Y边距以及高和宽。
请注意,我正在为此活动使用绝对布局。
这是我的完整活动代码:
公共类ListActivity扩展了Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
AbsoluteLayout ff = (AbsoluteLayout) this.findViewById(R.id.AbsoluteLayout1);
TableLayout tl = new TableLayout(this);
TableRow tr = new TableRow(this);
TextView tv = new TextView(this);
ScrollView myScrollView = new ScrollView(this);
// adding scrollview to current layout
ff.addView(myScrollView);
// adding TableLayout to current myScrollView
myScrollView.addView(tl);
/* not working
ViewGroup.LayoutParams lp = new LayoutParams(100 ,100);
myScrollView.setLayoutParams(lp);*/
myScrollView.setPadding(0, 210, 120, 0);
/* not working
LayoutParams layoutParams = new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
myScrollView.setLayoutParams(layoutParams); */
tr.addView(tv);
tv.setText("gewgewg");
tv.addView(tr);
}
}
答案 0 :(得分:1)
你可以试试..
myScrollView.setLayoutParams(new ViewGroup.LayoutParams(500, 900));
myScrollView.addView(home_linear, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
在你的布局中填写此滚动视图。对于x,你可以看到..