0

ここでは、線形レイアウトの下にテーブル レイアウトを表示するコードを示します。ここでは、スクロール ビューを contentview として設定していますが、画面に表示されるのはテーブル レイアウトのみです。

 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 には、子を 1 つだけ含める必要があります。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 に答える