protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView svv = new ScrollView(this);
svv.setLayoutParams(new ScrollView.LayoutParams(ScrollView.LayoutParams.WRAP_CONTENT, ScrollView.LayoutParams.WRAP_CONTENT));
LinearLayout linLayout = new LinearLayout(this);
linLayout.setOrientation(LinearLayout.VERTICAL);
LayoutParams linLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
LayoutParams lpView = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int colcount = 20;
int rowcount = 1;
TextView tv;
Button btn;
GridLayout grd;
GridLayout.LayoutParams gllop;
HorizontalScrollView svh;
for(int i = 0; i < 30; i++) {
tv= new TextView(this);
tv.setText("TextView " + i);
tv.setLayoutParams(lpView);
linLayout.addView(tv);
grd = new GridLayout(this);
grd.setColumnCount(colcount);
grd.setRowCount(rowcount);
grd.setBackgroundColor(Color.YELLOW);
for(int j = 0; j < 20; j++) {
gllop = new GridLayout.LayoutParams(GridLayout.spec(0), GridLayout.spec(j));
btn = new Button(this);
btn.setText("Button " + i +"."+j);
grd.addView(btn, gllop);
}
svh = new HorizontalScrollView(this);
svh.addView(grd);
linLayout.addView(svh);
}
svv.addView(linLayout);
setContentView(svv, linLayoutParam);
}
你的描述令我困惑。你可以添加你想要的和/或你現在的代碼截圖嗎? – Soana
如果你需要幫助,你應該事先寫出通用的例子... – Soana
非常感謝你甚至迴應@Soana,我爲自己工作,下面是相當簡單的答案。我只希望它可以幫助別人,使他們不會有我在這裏獲得任何幫助時遇到的相同問題。 :) – partynose