如何以编程方式向LinearLayout添加和删除布局行为 [英] How to add and remove layout behavior programmatically to LinearLayout
问题描述
您可以将 app:layout_behavior ="@ string/appbar_scrolling_view_behavior"
行为添加到XML声明中的 LinearLayout
中,但是我没有找到一种方法相同的代码.使用 CoordinatorLayout
,您可以调用 CoordinatorLayout.LayoutParams.setBehavior()
,但 LinearLayout.LayoutParams
上不提供此方法.有没有办法对 LinearLayout
做类似的事情?
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
?
推荐答案
您有点误解了 LayoutParams
概念.
LayoutParams
对象与封闭的 ViewGroup
相关,不与修改后的 ViewGroup
本身相关.
LayoutParams
object is related to the enclosing ViewGroup
, not to the modified ViewGroup
itself.
这篇关于如何以编程方式向LinearLayout添加和删除布局行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!