0

我有 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);
}

}
4

1 回答 1

1

你可以试试..

myScrollView.setLayoutParams(new ViewGroup.LayoutParams(500, 900));
myScrollView.addView(home_linear, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

在您的布局中填写此滚动视图。对于 x,y,您可以看到..

于 2013-03-03T17:25:25.903 回答