I'm developing an android app with fragments. While most of my layouts are pre-determined in the XML, I would like to programmatically insert a new view between views that were already loaded in a LinearLayout at startup.
How do I go about with this?
Thanks
LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view.
The Merge Tag intention allows you to merge two sequential and compatible XML tags into one larger tag. The tags to merge must have the same name and attributes.
Its possible to specify index while u dynamically add a view to a LinearLayout.
Set height of the first view as
android:layout_height="0dp"
android:layout_weight="1"
Set height = wrap_content
for the second view in XML
Then while u are adding new View dynamically, set its height = wrap_content
and add it to the parent LinearLayout
like this
parentLinearLayout.addView(childView, index);
//index = position where you want to insert the new view.
It might help you. :)
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