2013-12-12 52 views
1

我在活动中有EditText,Spinner,RadioButtonCheckbox。所以我需要在该活动中以编程方式使用ScrollView而不使用XML。滚动活动

我怎样才能不使用XML以编程方式创建scrollview?

在此先感谢。

+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);