-1

我是 Android 编程新手。我用 Java 制作了所有按钮,而不是使用 XML。现在我如何滚动我的按钮?这是我的代码:

public class GameZone extends Activity implements View.OnClickListener {
    private static final ColorStateList RED = null;

    LinearLayout rl;
    Button but1, but2, but3, but4, but5, but6, but7, but8, but9, but10, but11, but12;
    Button but13, but14, but15;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rl = new LinearLayout (this);
        rl.setOrientation(LinearLayout.VERTICAL);

        but1 = new Button (this);
        but1.setText("bu 1");
        but1.setTextSize(30);

        but2 = new Button (this);
        but2.setText("bu 2");
        but2.setTextSize(30);

        but3 = new Button (this);
        but3.setText("bu 3");
        but3.setTextSize(30);

        but4 = new Button (this);
        but4.setText("bu 4");
        but4.setTextSize(30);

        but5 = new Button (this);
        but5.setText("bu 5");
        but5.setTextSize(30);

        but6 = new Button (this);
        but6.setText("bu 6");
        but6.setTextSize(30);

        but7 = new Button (this);
        but7.setText("bu 7");
        but7.setTextSize(30);

        but8 = new Button (this);
        but8.setText("bu 8");
        but8.setTextSize(30);

        but9 = new Button (this);
        but9.setText("bu 9");
        but9.setTextSize(30);

        but10 = new Button (this);
        but10.setText("bu 10");
        but10.setTextSize(30);

        but11 = new Button (this);
        but11.setText("bu 11");
        but11.setTextSize(30);

        but12 = new Button (this);
        but12.setText("bu 12");
        but12.setTextSize(30);

        but1.setOnClickListener(this);
        but2.setOnClickListener(this);
        but3.setOnClickListener(this);
        but4.setOnClickListener(this);
        but5.setOnClickListener(this);
        but6.setOnClickListener(this);
        but7.setOnClickListener(this);
        but8.setOnClickListener(this);
        but9.setOnClickListener(this);
        but10.setOnClickListener(this);
        but11.setOnClickListener(this);
        but12.setOnClickListener(this);

        rl.addView(but1);
        rl.addView(but2);
        rl.addView(but3);
        rl.addView(but4);
        rl.addView(but5);
        rl.addView(but6);
        rl.addView(but7);
        rl.addView(but8);
        rl.addView(but9);
        rl.addView(but10);
        rl.addView(but11);
        rl.addView(but12);

        setContentView(rl);
    }
4

1 回答 1

0

把它LinearLayout放在ScrollView你的 XML 中。

例如,将其宽度设置为matchContent和高度设置fillParent为。

于 2013-06-27T18:44:34.057 回答