How to add and remove layout behavior programmatically to LinearLayout
Asked Answered
G

1

1

You can add the app:layout_behavior="@string/appbar_scrolling_view_behavior" behavior to a LinearLayout in the XML declaration but I haven't found a way to do the same in code. With a CoordinatorLayout you can call CoordinatorLayout.LayoutParams.setBehavior() but this method isn't available on LinearLayout.LayoutParams. Is there a way to do something similar for LinearLayout?

Grime answered 22/7, 2016 at 15:26 Comment(2)
https://mcmap.net/q/385746/-setting-app-layout_behavior-programmaticallyNocuous
@Akeshwar that doesn't work on LinearLayout because its LinearLayout.LayoutParams can't be cast to CoordinatorLayout.LayoutParams. In fact I have a comment under that same answer stating that fact.Grime
V
0

You're misunderstanding LayoutParams concept a bit.

LayoutParams object is related to the enclosing ViewGroup, not to the modified ViewGroup itself.

Vulcanize answered 7/9, 2016 at 5:58 Comment(3)
That's probably true but on CoordinatorLayout it can be done so I'm wondering if there is a way to do it on LinearLayout too.Grime
What exactly "can be done" on CoordinatorLayout? Take a good look a the question you posted your original comment. I do not do anything on the CoordinatorLayout itself. I do something on it's child ViewVulcanize
Not in CoordinatorLayout itself but when you have a view inside of it. What I meant was that when you had a view inside one you could add and remove LayoutParams programmatically. Not that you did that on CoordinatorLayout directly.Grime

© 2022 - 2024 — McMap. All rights reserved.