我想在一個LinearLayout或RelativeLayout中顯示兩個scrollView。 應將哪個屬性設置爲在屏幕頂部顯示第一個滾動視圖,並在第一個滾動視圖下方顯示第二個滾動視圖?在一個LinearLayout中顯示爲ScrollView
我已經嘗試,但在linearlayout它顯示我只有第一個scrollview和在relativelayout它顯示我只有第二個scrollView。
是的,我想動態地做所有這些,而不使用XML文件。
這裏是我的代碼
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.widget.TableLayout.LayoutParams;
public class TableFinal extends Activity {
LinearLayout linearMain, linearScrollView, linearTextview;
RelativeLayout relativeMain;
ScrollView scrollview;
HorizontalScrollView Hscrollview;
TableLayout tablelayout;
TableRow tablerow;
TextView textview;
LinearLayout.LayoutParams linearparmas;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
linearparmas=new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
relativeMain = new RelativeLayout(this);
// First Table
linearScrollView = new LinearLayout(this);
scrollview = new ScrollView(this);
Hscrollview = new HorizontalScrollView(this);
tablelayout = new TableLayout(this);
// First Table's First Row
tablerow = new TableRow(this);
linearTextview = new LinearLayout(this);
textview = new TextView(this);
textview.setText("11");
linearTextview.addView(textview);
tablerow.addView(linearTextview);
linearTextview = new LinearLayout(this);
textview = new TextView(this);
textview.setText("12");
linearTextview.addView(textview);
tablerow.addView(linearTextview);
tablelayout.addView(tablerow);
Hscrollview.addView(tablelayout);
scrollview.addView(Hscrollview);
linearScrollView.addView(scrollview);
relativeMain.addView(linearScrollView);
// first table complete
// second tabler start
linearScrollView = new LinearLayout(this);
scrollview = new ScrollView(this);
Hscrollview = new HorizontalScrollView(this);
tablelayout = new TableLayout(this);
// second Table's First Row
tablerow = new TableRow(this);
linearTextview = new LinearLayout(this);
textview = new TextView(this);
textview.setText("21");
linearTextview.addView(textview);
tablerow.addView(linearTextview);
linearTextview = new LinearLayout(this);
textview = new TextView(this);
textview.setText("22");
linearTextview.addView(textview);
tablerow.addView(linearTextview);
tablelayout.addView(tablerow);
Hscrollview.addView(tablelayout);
scrollview.addView(Hscrollview);
linearScrollView.addView(scrollview);
relativeMain.addView(linearScrollView);
// second tabler complete
setContentView(relativeMain);
}
}
謝謝。
你可以在這裏發佈你的代碼嗎?這會幫助你更多。 – Sandy 2011-03-11 06:30:36
嘿,在這裏我已經把我的代碼。 – Nirav 2011-03-11 10:47:55