如何创建一个可滚动布局 [英] how to create a scrollable layout
本文介绍了如何创建一个可滚动布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让一个布局动态,它应该是滚动的,因为我不知道我应该有多少文本字段和编辑文本字段绘制。画面如下图所示。
的LinearLayout布局=新的LinearLayout(本);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
的setContentView(布局);
解决方案
在滚动型
附上你的父母布局(LinearLayout中或RelativeLayout的)。这就是所有你需要解决这个问题。
滚动型滚动=新的滚动型(本);
scroll.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));的LinearLayout布局=新的LinearLayout(本);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));scroll.addView(布局,
新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));的setContentView(滚动);
Hi I am trying to make a layout dynamically and it should be scrollable because I will not know how many text fields and edit text fields I should draw. The picture is shown below.
LinearLayout layout=new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
setContentView(layout);
解决方案
Enclose your parent layout (LinearLayout or RelativeLayout) in a ScrollView
. Thats all you need to fix this.
ScrollView scroll = new ScrollView(this);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
LinearLayout layout=new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
scroll.addView(layout,
new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
setContentView(scroll);
这篇关于如何创建一个可滚动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文