我在活动中有EditText
,Spinner
,RadioButton
和Checkbox
。因此,我需要以编程方式在该活动中使用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);