0
    // customize linear layout       
    LinearLayout mainLayout = new LinearLayout(this);
    LinearLayout originWordsLayout = new LinearLayout(this);
    LinearLayout transWordsLayout = new LinearLayout(this);
    mainLayout.setOrientation(LinearLayout.HORIZONTAL);  
    originWordsLayout.setOrientation(LinearLayout.VERTICAL);  
    transWordsLayout.setOrientation(LinearLayout.VERTICAL);

    // set col 1
    TextView originTitle = new TextView(this);
    originTitle.setWidth(android.view.ViewGroup.LayoutParams.MATCH_PARENT);
    originTitle.setHeight(android.view.ViewGroup.LayoutParams.MATCH_PARENT);
    originTitle.setText("col1");
    originWordsLayout.addView(originTitle);


    // set col 2
    TextView transTitle = new TextView(this);
    transTitle.setWidth(android.view.ViewGroup.LayoutParams.MATCH_PARENT);
    transTitle.setHeight(android.view.ViewGroup.LayoutParams.MATCH_PARENT);
    transTitle.setText("col2");
    transWordsLayout.addView(transTitle);



    mainLayout.addView(originWordsLayout);
    mainLayout.addView(transWordsLayout);
    setContentView(mainLayout);

and when I run my app, there's nothing on the screen anyone tell me what's wrong with my code? what I want to do is dynamically add some View to my layout

4

1 回答 1

0

originWordsLayout and transWordsLayout should be WRAP_CONTENT and so the TextView transTitle and TextView originTitle instead of MATCH_PARENT

于 2013-05-10T07:12:15.397 回答