我正在实现包含多个可点击和动态生成的文本视图的视图。我想以段落样式显示它们。这是我的代码。对不起,如果我弄错了。
这是我所做的:
private void init() {
//int strLength=arrayList.size();
arrayList=new ArrayList<String>();
arrayList.add("Name");
arrayList.add("Address");
arrayList.add("obj");
arrayList.add("age");
RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.relativeLayout);
int x=10;
int y=30;
for (int i=0; i<arrayList.size(); i++) {
String str=arrayList.get(i).toString();
tv = new TextView(this);
tv.setId(i);
tv.setText(str);
tv.setTextSize(24);
tv.setOnClickListener(this);
tv.setClickable(true);
tv.setFocusable(true);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
if(arrayList.get(i).equals("Name")){
y=y+10;
x=60;
}
else
{
x=x+arrayList.size()+60;
}
if(i>0){
params.addRule(RelativeLayout.START_OF, i);
}
tv.setPadding(x+20, y,0,0);
tv.setEms(25);
tv.setWidth(80);
tv.setLayoutParams(params);
rl.addView(tv, params);
int x1=rl.getWidth();
rl.getLayoutParams();
Log.e("x===",String.format("%d",x1));
Log.e("x===",String.format("%d",x));
}
}