Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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 以编程方式相对定位_Android - Fatal编程技术网

Android 以编程方式相对定位

Android 以编程方式相对定位,android,Android,我正在以编程方式使用相对布局。它有多个文本视图,但显示水平而不是垂直。如何以编程方式将它们作为段落视图获取 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLa

我正在以编程方式使用相对布局。它有多个文本视图,但显示水平而不是垂直。如何以编程方式将它们作为段落视图获取

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
                params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);


    int x=10;
    int y=30;
    for(int i=0;i<arrayList.size();i++)
    {
                   String str=arrayList.get(i);
        int strLength=arrayList.size();
        if(arrayList.get(i).equals("Name")){
            y=y+10;
            x=65;
        }
        else
        {
            x=x+strLength+60;
        }

        //tv=(TextView) findViewById(R.id.tv1);
        tv=new TextView(this);
        tv.setText(arrayList.get(i).toString());
        tv.setPadding(x, y, 0, 0);
        layout.addView(tv, params);

    }
     scroll.addView(layout);
    this.setContentView(scroll);
RelativeLayout.LayoutParams params=新的RelativeLayout.LayoutParams(LayoutParams.FILL\u父级,LayoutParams.WRAP\u内容);
参数addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE);
int x=10;
int y=30;

for(int i=0;i
RelativeLayout
没有名为
Orientation
的属性。您必须为每个
文本视图
指定id,并添加如下规则

tv.addRule(RelativeLayout.BELOW, someOtherView.getId());
所以在你的情况下,我认为会是这样:

for(int i=0;i<arrayList.size();i++)
    {
        String str=arrayList.get(i);
        int strLength=arrayList.size();
        if(arrayList.get(i).equals("Name")){
            y=y+10;
            x=65;
        }
        else
        {
            x=x+strLength+60;
        }

        //tv=(TextView) findViewById(R.id.tv1);
                    tv=new TextView(this);
                    tv.setId(i);
                    tv.setText(arrayList.get(i).toString());
                         tv.setPadding(x, y, 0, 0);
                    layout.addView(tv, params);
                    if (i>0)
                        tv.addRule(RelativeLayout.BELOW, i-1);
    }
for(int i=0;i0)
tv.addRule(相对论,见下文,i-1);
}

希望这能有所帮助。

您只需将规则添加到下面的params
RelativeLayout.中

像这样试试

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
                    params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);


        int x=10;
        int y=30;
        for(int i=0;i<arrayList.size();i++)
        {
                       String str=arrayList.get(i);
            int strLength=arrayList.size();
            if(arrayList.get(i).equals("Name")){
                y=y+10;
                x=65;
            }
            else
            {
                x=x+strLength+60;
            }

            //tv=(TextView) findViewById(R.id.tv1);
            tv=new TextView(this);
            tv.setText(arrayList.get(i).toString());
            tv.setPadding(x, y, 0, 0);
           if(layout.getChildCount() != 0)
                params.addRule(RelativeLayout.BELOW, (layout.getChildAt(layout.getChildCount() - 1)).getId());
            layout.addView(tv, params);

        }
         scroll.addView(layout);
        this.setContentView(scroll);
RelativeLayout.LayoutParams params=新的RelativeLayout.LayoutParams(LayoutParams.FILL\u父级,LayoutParams.WRAP\u内容);
参数addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE);
int x=10;
int y=30;

对于(int i=0;i
RelativeLayout
s)没有方向。谢谢..它工作正常..但是如果我想将这些文本视图显示为段落样式,我应该怎么做?如果这解决了问题,那么请将下面您认为最可接受的答案之一标记为正确,以便其他人受益..至于您的查询,请参阅