如何以编程方式向LinearLayout添加和删除布局行为 [英] How to add and remove layout behavior programmatically to LinearLayout

查看:89
本文介绍了如何以编程方式向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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆