问题
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
?
回答1:
You're misunderstanding LayoutParams
concept a bit.
LayoutParams
object is related to the enclosing ViewGroup
, not to the modified ViewGroup
itself.
来源:https://stackoverflow.com/questions/38530196/how-to-add-and-remove-layout-behavior-programmatically-to-linearlayout