开发者

Adding layout dynamically to ScrollView android

开发者 https://www.devze.com 2023-01-26 16:51 出处:网络
I want to add xml layout dynamically to scrollview in my application, but it is showing an error. This is my code:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消