2010-10-20 180 views

回答

1

編程添加TextView(或一般的View)到佈局(或一般的ViewGroup)是可能的,請檢查ViewGroup的public void addView (View child, int index)方法。

5

完整的解決方案:

View parent; //parent view where to add 


    ViewGroup layout=new LinearLayout(context); 
    layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 
    TextView tv1=new TextView(context); 
    tv1.setText("Test1"); 
    TextView tv2=new TextView(context); 
    tv2.setText("Test2"); 
    layout.addView(tv1); 
    layout.addView(tv2); 
    parent.addView(layout); 
+1

哪裏聲明 「背景」?它在任何地方初始化 – 2013-11-26 09:00:50