小编Lop*_*ano的帖子

以编程方式创建一个新的TextView,然后将其显示在另一个TextView下面

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<length;i++){
    TextView tv=new TextView(getApplicationContext());
    tv.setText(textArray[i]);
    relativeParams.addRule(RelativeLayout.BELOW, tv.getId());
    layout.addView(tv, relativeParams);
}
Run Code Online (Sandbox Code Playgroud)

我需要做那样的事情......所以它会显示为

one
two
asdfasdfsomething
Run Code Online (Sandbox Code Playgroud)

屏幕上..

java android textview android-relativelayout

46
推荐指数
4
解决办法
17万
查看次数

标签 统计

android ×1

android-relativelayout ×1

java ×1

textview ×1