我有 scroll-view 和 table-layout , row-table 。
现在我想在编程代码而不是 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);
}
}