为什么下面的android代码什么都没显示

时间:2013-05-10 07:10:21

标签: android

    // 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);

当我运行我的应用程序时,屏幕上没有任何内容 有谁告诉我我的代码有什么问题? 我想要做的是动态地将一些视图添加到我的布局

1 个答案:

答案 0 :(得分:0)

originWordsLayouttransWordsLayout应为WRAP_CONTENT,因此TextView transTitleTextView originTitle代替MATCH_PARENT