java-以编程方式创建一个新的TextView,然后将其显示在另一个TextVi下面
String[] textArray={"one","two","asdasasdf asdf dsdaa"};
int length=textArray.length;
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
for(int i=0;i
TextView tv=new TextView(getApplicationContext());
tv.setText(textArray[i]);
relativeParams.addRule(RelativeLayout.BELOW, tv.getId());
layout.addView(tv, relativeParams);
}
我需要做类似的事情..所以它将显示为
one
two
asdfasdfsomething
屏幕上..
4个解决方案
69 votes
如果使用RelativeLayout并不重要,则可以使用LinearLayout,然后执行以下操作:
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientatio