如何添加动态创建的LinearLayout到滚动型? [英] How to add a dynamically created LinearLayout to a ScrollView?
本文介绍了如何添加动态创建的LinearLayout到滚动型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要动态地添加一些小部件,像这样:
I want to dynamically add some widgets like so:
LinearLayout llay = new LinearLayout(this);
llay.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.weight = 1.0f;
CheckBox cb = new CheckBox(getApplicationContext());
cb.setText("1");
cb.setLayoutParams(llp);
llay.addView(cb);
ScrollView svh = (ScrollView) findViewById(R.id.scrollViewHost);
svh.AddView(llay);
...但我得到的方法AddView(LinearLayout中)是未定义的类型滚动型
...but I'm getting, "The method AddView(LinearLayout) is undefined for the type ScrollView"
所以,我应该怎么办的的LinearLayout添加到现有的滚动型?
So what should I do to add the LinearLayout to the existing ScrollView?
推荐答案
由于Java是区分大小写? AddView()
!= addView()
。同时,(虽然不是问题的根源),注意,滚动型
只能有一个孩子。
Because Java is case sensitive? AddView()
!= addView()
. Also (though not the root of the problem), note that a ScrollView
can only have one child.
这篇关于如何添加动态创建的LinearLayout到滚动型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文