Setting app:layout_behavior programmatically

前端 未结 3 634
爱一瞬间的悲伤
爱一瞬间的悲伤 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 09:06

    Accepted answer is correct but the provided code is not compilable. So here is a complete example

    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) 
    view.getLayoutParams();
    
    params.setBehavior(new AppBarLayout.ScrollingViewBehavior(view.getContext(), null));
    

    2nd param is AttributeSet and it is fine to have it as null although it is not marked as Nullable in support lib.

提交回复
热议问题