Horizontal ListView in Android?

后端 未结 19 1197
深忆病人
深忆病人 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:19

    As per Android Documentation RecyclerView is the new way to organize the items in listview and to be displayed horizontally

    Advantages:

    1. Since by using Recyclerview Adapter, ViewHolder pattern is automatically implemented
    2. Animation is easy to perform
    3. Many more features

    More Information about RecyclerView:

    1. grokkingandroid.com
    2. antonioleiva.com

    Sample:

    survivingwithandroid.com

    Just add the below block to make the ListView to horizontal from vertical

    Code-snippet

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

提交回复
热议问题