1

I am using the scrolling activity generated by Android Studio. So something like this:

enter image description here

It uses an @include tag in the XML to load the content of the activity.

I need to change the content inside this NestedScrollView to something else. So I have been using this:

LayoutInflater inflater = 
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            progressContent = inflater.inflate(R.layout.content_progress, null);
            scrollView.removeView(normalContent);
            scrollView.addView(progressContent);

And it works, but it doesn't use the ConstraintLayout of the progressContent correctly, it ignored all the bias values and only keeps hard set margins and paddings.


In this question, people suggested to use ´setContentView` but since I only have to change the inner content, not the whole layout, it's not the right solution:
How to set layout dynamically in android

In this one it was suggested to use ViewStubs instead of @include:
How can I programmatically include layout in Android?
But this only resulted in a completely broken CollapsingToolbarLayout and the layout parameters of the second view got discarded regardless.


What is the correct way of doing this?

Big_Chair
  • 2,781
  • 3
  • 31
  • 58

0 Answers0