LinearLayoutManager setReverseLayout() == true but items stack from bottom

前端 未结 4 555
自闭症患者
自闭症患者 2020-11-27 17:26

This seems like it would be an easy solution, but it seems that setting

private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private Li         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 18:14

    The accepted answer works well and I went through a hardship to make it work as I was getting can not resolve method setReverseLayout error.

    Then after searching for solutions I found there was a silly mistake out there. I was using RecyclerView.LayoutManager instead of LinearLayoutManager.

    So I thought to remove the confusions around here I need to put it as an answer.

    Do not use RecyclerView.LayoutManager instead of LinearLayoutManager

    // Declare your RecyclerView and the LinearLayoutManager like this 
    private RecyclerView mRecyclerView;
    private LinearLayoutManager mLayoutManager;
    

    ...

    // Now set the properties of the LinearLayoutManager 
    mLayoutManager = new LinearLayoutManager(MainActivity.this);
    mLayoutManager.setReverseLayout(true);
    mLayoutManager.setStackFromEnd(true);
    
    // And now set it to the RecyclerView
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(yourAdapter);
    

提交回复
热议问题