Dynamically add layout to ScrollView android

I want to add an xml layout dynamically to scrollview in my application, but it shows an error.

This is my code:

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" and "headertwo.xml" are my two xml layout files.

+3
source share
1 answer

maybe

ScrollView is a FrameLayout, which means you have to put one child in it, containing all the contents for scrolling; this child himself can be a layout manager with a complex hierarchy of objects.

But we will need to make sure that XML is certain.

-1
source

Source: https://habr.com/ru/post/1776842/


All Articles