Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用java代码将scrollview添加到布局_Android - Fatal编程技术网

Android 使用java代码将scrollview添加到布局

Android 使用java代码将scrollview添加到布局,android,Android,我已经创建了以下布局。它有两个相对布局和一个滚动视图,下面的代码包含布局的标题。我需要在其中创建我将使用循环的工作表 RelativeLayout inner=new RelativeLayout(this); inner.setBackgroundColor(Color.RED); outerLayout=new RelativeLayout(this); ScrollView scroll=new ScrollView(this); TextView qty=new Te

我已经创建了以下布局。它有两个相对布局和一个滚动视图,下面的代码包含布局的标题。我需要在其中创建我将使用循环的工作表

  RelativeLayout inner=new RelativeLayout(this);
  inner.setBackgroundColor(Color.RED);
  outerLayout=new RelativeLayout(this);
  ScrollView scroll=new ScrollView(this);
  TextView qty=new TextView(this);
  qty.setId(1111);
  inner.addView(qty);
  qty.setTextColor(Color.WHITE);
  qty.setText("Qty");

  setContentView(outerLayout); 
  RelativeLayout.LayoutParams p=new          RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,30);
  p.addRule(RelativeLayout.RIGHT_OF,qty.getId())

    ;
   p.leftMargin=30;

    TextView partNo=new TextView(this);
    partNo.setText("Part no");
    partNo.setId(2222);
    partNo.setLayoutParams(p);
    partNo.setTextColor(Color.WHITE);


    inner.addView(partNo);

    RelativeLayout.LayoutParams descLayout=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,30);
    descLayout.addRule(RelativeLayout.RIGHT_OF,partNo.getId())

    ;
    descLayout.leftMargin=30;

    TextView desc=new TextView(this);
    desc.setText("Description");
    desc.setId(3333);
    desc.setLayoutParams(descLayout);
    desc.setTextColor(Color.WHITE);


    inner.addView(desc);


    RelativeLayout.LayoutParams commentLayout=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,30);
    commentLayout.addRule(RelativeLayout.RIGHT_OF,desc.getId())

    ;
    commentLayout.leftMargin=30;

    TextView comment=new TextView(this);
    comment.setText("Comments");
    comment.setId(4444);
    comment.setLayoutParams(commentLayout);
    comment.setTextColor(Color.WHITE);


    inner.addView(comment);


    RelativeLayout.LayoutParams retailLayout=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,50);
    retailLayout.addRule(RelativeLayout.RIGHT_OF,comment.getId())

    ;
    retailLayout.leftMargin=30;

    TextView retail=new TextView(this);
    retail.setText("Retail \n Reference");
    retail.setId(5555);
    retail.setLayoutParams(retailLayout);
    retail.setTextColor(Color.WHITE);


    inner.addView(retail);
    scroll.setVerticalScrollBarEnabled(true);
    scroll.setHorizontalScrollBarEnabled(true);


    scroll.addView(inner);

    outerLayout.addView(scroll);

我试图将滚动视图添加到布局中,但不幸的是,我无法看到滚动视图。请帮助我如何将滚动视图添加到上面的布局中。

不确定这是否是您的问题,但我看不到您在滚动视图上设置布局参数的位置。

我需要设置哪些参数请解释您正在将其添加到RelativeLayout例如:RelativeLayout.LayoutParams p=新的RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL\u父级,ViewGroup.LayoutParams.FILL\u父级);滚动.setLayoutParams(p);