android - 如何在android中添加多个按钮到scrollview

标签 android button scrollview

我想实现这个功能:动态添加多个按钮到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/

相关文章:

android - 找不到参数[com.google.firebase:firebase-database:11.0.4]的方法Implementation()

使用 v7 appcompat 库的 Android 后向兼容性

android studio 1.0 库项目无法设置applicationId。 applicationId 在默认配置中设置为 ''

android - ObservableScrollView 中的自定义 ViewPager 无法正确测量高度

javascript - 移动友好的工具提示在 Android 浏览器中不起作用

ios - Facebook 和 Twitter 分享按钮停止工作

python - PyQt 中的布局由 QWidgetItems 而不是 QPushButtons 组成,并且没有属性文本

javascript - 使用 HTML 和 JavaScript 的 WebGL 全屏按钮?

android - LinearLayout 中的滚动问题

在 Scrollview 中滚动时 Android v2 MapFragment 抖动