How to build a Horizontal ListView with RecyclerView?

前端 未结 13 1175
小鲜肉
小鲜肉 2020-11-22 04:53

I need to implement a horizontal listview in my Android application. I did a bit of research and came across How can I make a horizontal ListView in Android? and Horizontal

13条回答
  •  無奈伤痛
    2020-11-22 05:46

    Is there a better way to implement this now with Recyclerview now?

    Yes.

    When you use a RecyclerView, you need to specify a LayoutManager that is responsible for laying out each item in the view. The LinearLayoutManager allows you to specify an orientation, just like a normal LinearLayout would.

    To create a horizontal list with RecyclerView, you might do something like this:

    LinearLayoutManager layoutManager
        = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    
    RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
    myList.setLayoutManager(layoutManager);
    

提交回复
热议问题