滚动活动

时间:2013-12-12 04:01:24

标签: android

我在活动中有EditTextSpinnerRadioButtonCheckbox。因此,我需要以编程方式在该活动中使用ScrollView而不使用XML。

如何在不使用XML的情况下以编程方式创建scrollview?

先谢谢。

1 个答案:

答案 0 :(得分:1)

//Create the ScrollView
ScrollView scroll = new ScrollView(this);
scroll.setBackgroundColor(android.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                                             LayoutParams.FILL_PARENT));

//Get the base layout for your Activity and add the scroll view to it.
ViewGroup root = (ViewGroup)findViewById(R.id.content);
root.addView(scroll);

//Add your layout here which contains the EditText, Spinner and RadioButton and CheckBox.
scroll.addView(yourExistingLayout);