Adding layout dynamically to ScrollView android
I want to add xml layout dynamically to scrollview in my application, but it is showing an error.
This is my code:
LinearLayout ll = (LinearLayout)findViewById(R.id.myContent1);
LayoutInflater vi = (LayoutInflater)getSystemService(Context.开发者_如何学CLAYOUT_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" and "headertwo.xml" are my two xml layout files.
Probably
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects.
But we would need to see the XML to be sure.
精彩评论