如何在我的布局中动态添加滚动视图?一旦我得到那个scrollview添加我想添加一个linearlayout里面,所以我现在可以在该linearlayout中添加控件?动态添加滚动视图在滚动视图中的布局和线性布局
4
A
回答
5
5
我希望它会帮助你。
试试这个代码...
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout rl=(RelativeLayout)findViewById(R.id.rl);
ScrollView sv = new ScrollView(this);
sv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
ll.setOrientation(1);
sv.addView(ll);
for(int i = 0; i < 20; i++)
{
Button b = new Button(this);
b.setText("Button "+i);
ll.addView(b);
}
rl.addView(sv);
/* If you want to set entire layout as dynamically, then remove below lines in program :
* setContentView(R.layout.activity_main);
* RelativeLayout rl=(RelativeLayout)findViewById(R.id.rl);
* rl.addView(sv);
*
* And Add below line :
* this.setContentView(sv);
*/
}
-1
试试这个它会工作:
TextView tv = new TextView(this);
tv.setText(msg);
tv.setMovementMethod(new ScrollingMovementMethod());
setContentView(tv);
-1
你可以用滚动型内小部件。这里有一个简单的例子:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txt"/>
</LinearLayout>
</ScrollView>
如果你想这样做代码:
ScrollView sv = new ScrollView(this);
//Add your widget as a child of the ScrollView.
sv.addView(wView);
相关问题
- 1. 将滚动视图添加到布局
- 2. 的Xcode - 滚动视图 - 自动布局
- 3. mono for android - 动态添加布局到滚动视图
- 4. 滚动视图滚动列表视图不是布局
- 5. 将视图添加到滚动视图的底部布局
- 6. 以编程方式添加视图(线性)布局(即滚动视图内)
- 7. android textview scrollview在布局滚动视图
- 8. 在线性布局中动态添加视图
- 9. 滚动查看不滚动子视图在自动布局
- 10. 设置水平滚动视图布局
- 11. android布局 - 滚动视图不显示
- 12. 滚动视图相对布局问题
- 13. 问题与滚动视图内布局
- 14. 可滚动布局重叠视图
- 15. 滚动后滚动列表视图中的布局
- 16. 如何在此布局中添加滚动视图?
- 17. 带滚动视图的多个线性布局?
- 18. Android:使用三种线性布局的水平滚动视图
- 19. 如何滚动到长滚动视图布局的顶部?
- 20. 滚动视图内部的相对布局不可滚动
- 21. Android线性布局不填充滚动视图
- 22. 滚动视图无法处理线性布局
- 23. 在滚动视图布局的视图底部锁定Imageview
- 24. Android的滚动视图吃了添加布局
- 25. 添加视图布局底部的滚动型
- 26. 在Android中动态添加视图与布局权重属性
- 27. 无法滚动视图添加到布局
- 28. ViewPager添加滚动视图到布局后不工作
- 29. 以相对布局将滚动条添加到动态表格视图
- 30. 自动布局与动态子视图