简体   繁体   English

如何为scoll视图设置XY和高宽度

[英]how to set X Y and hight width for scoll view

I have scroll-view and table-layout , row-table . 我有滚动视图和表布局,行表。

now i want to set X and Y margins and high and width for each one in programming code not xml . 现在我想在编程代码而不是xml中为每个设置X和Y边距以及高和宽。

note , I'm using Absolute layout for this activity . 注意,我正在为此活动使用绝对布局。

this is my full code of activity : 这是我完整的活动代码:

public class ListActivity extends Activity { 公共类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);
}

}

You can try with.. 您可以尝试..

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

Fill this scroollview in your layout.For x,y you can see.. 将此scroollview填充到您的布局中。对于x,y,您可以看到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM