我想实现这个功能:动态添加多个按钮到scrollview,如果scrollview超过一定高度,会自动显示滚动条。
你能给我一些建议吗?
最佳答案
检查以下代码 fragment :
// Find the ScrollView
ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView1);
// Create a LinearLayout element
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
// Add Buttons
Button button = new Button(this);
button.setText("Some text");
linearLayout.addView(button);
// Add the LinearLayout element to the ScrollView
scrollView.addView(linearLayout);
引自How do I add elements dynamically to a view created with XML .
关于android - 如何在android中添加多个按钮到scrollview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14920535/