Horizontal ListView in Android?

后端 未结 19 947
深忆病人
深忆病人 2020-11-22 03:54

Is it possible to make the ListView horizontally? I have done this using a gallery view, but the selected item comes to the center of the screen automatically.

19条回答
  •  清酒与你
    2020-11-22 04:23

    This is a little (very) late, but I'm posting this in case someone comes by this later.

    The Support Library as of the Android L preview has a RecyclerView that does exactly what you want.

    Right now, you can only get it through the L preview SDK and you need to set your minSdk to L. But you can copy all of the necessary files into your project and use them that way until L is officially out.

    You can download the preview docs here.

    Warning: The API for Recycler View may change and it may have bugs.

    Updated

    The source code for horizontal listview is:

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

提交回复
热议问题