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;iRelativeLayout
没有名为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);
}
希望这能有所帮助。您只需将规则添加到下面的paramsRelativeLayout.中
像这样试试
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;iRelativeLayout
s)没有方向。谢谢..它工作正常..但是如果我想将这些文本视图显示为段落样式,我应该怎么做?如果这解决了问题,那么请将下面您认为最可接受的答案之一标记为正确,以便其他人受益..至于您的查询,请参阅