I would like to take an existing ScrollView
with a view in it, and add more views, dynamically (at runtime) to the ScrollView
container.
Is it possible to add these views without having to create a new layout and inflate it? If so, what's the general process for adding these views dynamically?
For the sake of this question, assume the views are TextView
...
Thanks!
ScrollView and HorizontalScrollView has same attributes, the only difference is scrollView scroll the child items in vertical direction while horizontal scroll view scroll the child items in horizontal direction.
Put simply, an inflater allows you to create a View from a resource layout file so that you do not need to create everything programmatically.
A ScrollView
can only have one child, so it doesn't make sense to add more children to it directly. Lets say your ScrollView
has a LinearLayout
inside of it, then you can add more views to the LinearLayout
:
LinearLayout layout = findViewById(R.id.my_linear_layout);
TextView textView = new TextView(this);
layout.addView(textView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With