我想动态添加一些小部件,如下所示:
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) 方法对于 ScrollView 类型未定义”
那么我应该怎么做才能将LinearLayout添加到现有的ScrollView中呢?
最佳答案
因为Java区分大小写? AddView()
!= addView()
。另外(尽管不是问题的根源),请注意 ScrollView 只能有一个 subview 。
关于android - 如何将动态创建的LinearLayout添加到ScrollView中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9509842/