I am writing a simple android app that has a vertical parent LinearLayout. As children, I want a ScrollView, two edit texts, and then a button.
Inside the scrollView is a number of buttons. When I put many buttons in there, the ScollView takes up the entire screen. I still want the EditTexts and final button to be visible.
public class MainActivity extends AppCompatActivity
{
LinearLayout mainLayout;
ScrollView scrollView;
LinearLayout fileSelector;
EditText name;
EditText password;
Button submit;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mainLayout = new LinearLayout(this);
mainLayout.setOrientation(LinearLayout.VERTICAL);
fileSelector = new LinearLayout(this);
fileSelector.setOrientation(LinearLayout.VERTICAL);
scrollView = new ScrollView(this);
scrollView.addView(fileSelector);
mainLayout.addView(scrollView);
name = new EditText(this);
password = new EditText(this);
submit = new Button(this);
submit.setText("Login");
for(int i=0; i<100; i++)
{
Button b = new Button(this);
b.setText("hello");
fileSelector.addView(b);
}
mainLayout.addView(name);
mainLayout.addView(password);
mainLayout.addView(submit);
setContentView(mainLayout);
}
public void onClick(View v)
{
}
}
I would like to know the solution programatticaly.