【问题标题】:Dynamically creates TextView boxes动态创建 TextView 框
【发布时间】:2011-06-06 07:06:17
【问题描述】:

我想动态创建多个 TextView 框,如果我在 Edittext 中输入 2,它想创建 2 个 TextView,如果我在 EditText 中输入 5,它想创建 5 个 TextView,依此类推……谁能帮助我。 ..

提前致谢,

【问题讨论】:

    标签: android android-layout android-emulator android-widget


    【解决方案1】:

    首先你需要得到父布局。如果是,比如LinearLayout的意思,你可以使用addView(view)添加textview。

    letterTextView = new TextView[length];
    for (int Index = 0; Index < length; Index++) 
            {
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                layoutParams.setMargins(0, 0, 25, 0);
                letterTextView[Index] = new TextView(FriendsPanel.this);
                letterTextView[Index].setTextSize(20);
                letterTextView[Index].setTextColor(Color.WHITE);
                letterTextView[Index].setText("TextView"+letterIndex);
    
                linearLayout.addView(letterTextView[Index], layoutParams);
            }
    

    【讨论】:

    • 是的。如果您认为答案对您有帮助,请接受。
    猜你喜欢
    • 2016-06-03
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多