Inflating view above RecyclerView in FrameLayout

后端 未结 4 622
轮回少年
轮回少年 2021-01-20 10:55

On a button click, I am attempting to inflate an EditText above a RecyclerView. But instead of the EditText being added to the top of the layout, t

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 11:47

    Is this TextView related to items in RecyclerView such that you want to treat it as an item? If so, add EditText as a new view type to your adapter (to index 0) and call notifyItemInserted(0). In response, RecyclerView will call onBind where you can return your EditText. This way, RecyclerView can nicely animate Views down while fading in EditText. If you can post your adapter, I'm happy to post an example comde.

    If you don't want to add it inside the RecyclerView, you have two options: - Set top margin on the RecyclerView or top padding when you add the edit text. - Use a linear layout instead of a frame layout and use TransitionManager to animate.

    I still think you should consider adding it as an item to your adapter so that LayoutManager can handle focus changes etc. (and it also moves w/ the rest of the list)

提交回复
热议问题