Setting app:layout_behavior programmatically

前端 未结 3 639
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 08:13

I have a coordinator layout with a recyclerview which I would like to add programmatically. The reason why it\'s added programatically is because different fragments which infla

3条回答
  •  攒了一身酷
    2021-01-31 08:54

    To enable and disable layout_behavior programatically with kotlin use this code :

    fun enableLayoutBehaviour() {
        val param: CoordinatorLayout.LayoutParams = swipeRefreshView.layoutParams as CoordinatorLayout.LayoutParams
        param.behavior = AppBarLayout.ScrollingViewBehavior()
    }
    
    fun disableLayoutBehaviour() {
        val param: CoordinatorLayout.LayoutParams = swipeRefreshView.layoutParams as CoordinatorLayout.LayoutParams
        param.behavior = null
    }
    

    Note: replace swipeRefreshView with your view

提交回复
热议问题