我想在一个 LinearLayout 或 RelativeLayout 中显示两个 scrollView。应该将哪个属性设置为在屏幕顶部显示第一个 Scrollview 并在第一个 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);
}
}
谢谢你。