我想在我的应用程序中动态添加 xml 布局到 ScrollView ,但显示错误。
这是我的代码:
LinearLayout ll = (LinearLayout)findViewById(R.id.myContent1);
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vv = vi.inflate(R.layout.headerone, null);
ll.addView(vv);//, new LinearLayout.LayoutParams(ll.getLayoutParams().width, ll.getLayoutParams().height));
View vv2 = vi.inflate(R.layout.headertwo, null);
ll.addView(vv2);//, new LinearLayout.LayoutParams(ll.getLayoutParams().width, ll.getLayoutParams().height));
View vv3 = vi.inflate(R.layout.headerone, null);
ll.addView(vv3);
“headerone.xml”和“headertwo.xml”是我的两个xml布局文件。
最佳答案
可能
ScrollView 是一种 FrameLayout,这意味着您应该在其中放置一个子项,其中包含要滚动的全部内容;这个 child 本身可能是一个布局管理器,具有复杂的对象层次结构。
但我们需要查看 XML 才能确定。
关于android - 动态添加布局到 ScrollView android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4275097/