How to set RecyclerView app:layoutManager=“” from XML?

前端 未结 6 1161
孤城傲影
孤城傲影 2020-12-02 06:08

How to set RecyclerView layoutManager from XML?

    

        
6条回答
  •  囚心锁ツ
    2020-12-02 06:36

    And I came here looking for androidx version though it was pretty easy to figure out, here it is

    LinearLayoutManager:

    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
    

    Example:

    
    

    GridLayoutManager:

    app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
    

    Example:

    
    

    As you can see in examples above you can control the orientation from within xml using

    android:orientation="vertical"
    

    and

    android:orientation="horizontal"
    

    And to set the number of columns for GridLayoutManager using

    app:spanCount="2"
    

提交回复
热议问题