我想在我以編程方式創建的相對佈局中以垂直方向放置滾動。但我的紙捲不起作用。誰能幫我? 這裏是我正在使用的代碼:Android中的動態RelativeLayout:滾動不工作
RelativeLayout layout = (RelativeLayout) findViewById(R.id.screen1);
for (i = 1; i < 20; i++) {
RelativeLayout.LayoutParams p = new
RelativeLayout.LayoutParams(
150,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
layout.setScrollContainer(true);
ScrollView vscroll = new ScrollView(this);
vscroll.setFillViewport(true);
layout.setVerticalScrollBarEnabled(true);
layout.addView(vscroll);
p.addRule(RelativeLayout.BELOW, i-1);
p.addRule(RelativeLayout.CENTER_HORIZONTAL);
Button buttonView = new Button(this);
buttonView.setId(i);
buttonView.setText(i);
buttonView.setLayoutParams(p);
buttonView.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Dialog(((Button)arg0).getId());
} });
layout.addView(buttonView, p);
}
所以我必須把這樣的事情? vscroll.add(button); – Victor 2011-04-08 19:31:36