0

这是我在线性布局下方显示表格布局的代码。这里我将滚动视图设置为内容视图。但只有表格布局显示在屏幕上。这里有任何布局问题。请帮助我,谢谢。

 ScrollView scrollView = new ScrollView(this);
            LinearLayout ll = new LinearLayout(getApplicationContext());
    ll.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));

            Button btn1 = new Button(this);
            btn1.setText("Button1");
            ll.addView(btn1);
            btn1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
            TableLayout resultLayout = new TableLayout(this);
            resultLayout.setStretchAllColumns(true);
            resultLayout.setShrinkAllColumns(true);

这里尝试将线性布局放在表格布局上方,现在只显示线性布局

 LinearLayout ll = new LinearLayout(getApplicationContext());
        ll.setOrientation(LinearLayout.VERTICAL);
        ll.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));

        // Set the TextView for the Question
        TextView tv1 = new TextView(getApplicationContext());
        tv1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        tv1.setText("HI");
        ll.addView(tv1);
ScrollView scrollView = new ScrollView(this);
        TableLayout resultLayout = new TableLayout(this);
        resultLayout.setStretchAllColumns(true);
        resultLayout.setShrinkAllColumns(true);

//这里我有表格行代码

ll.addView(scrollView);
setContentView(ll);

现在根据您的答案将线性布局设置为内容视图滚动视图仅包含表格布局。但为什么它没有显示在屏幕上

4

2 回答 2

1

ScrollViewandroid 中的 s 应该只包含一个孩子。所以我可以建议你在LinearLayout里面添加一个ScrollView然后在这个里面添加其他组件LinearLayout

于 2013-09-14T06:26:13.967 回答
0

检查这个:\

LinearLayout ll = new LinearLayout(getApplicationContext()); 
ll.setOrientation(LinearLayout.VERTICAL); 
ll.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.WRAP_CONTENT)); 

// Set the TextView for the Question 
TextView tv1 = new TextView(getApplicationContext()); 
tv1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.WRAP_CONTENT)); 
tv1.setText("HI"); 
ll.addView(tv1); 
ScrollView scrollView = new ScrollView(this); 
scrollView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.WRAP_CONTENT)); 
TableLayout resultLayout = new TableLayout(this); 
resultLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.WRAP_CONTENT)); 
scrollView.addView(resultLayout);   
resultLayout.setStretchAllColumns(true); 
resultLayout.setShrinkAllColumns(true); 
ll.addView(scrollView);
于 2013-09-14T07:32:26.587 回答