Horizontal ListView in Android?

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

    There is a great library for that, called TwoWayView, it's very easy to implement, just include the project library into your work space and add it as a library project to your original project, and then follow the following steps which are originally mentioned here:

    First, let's add a style indicating the orientation of the ListView (horizontal or vertical) in (res/values/styles.xml):

    
    

    Then,

    In your Layout XML, use the following code to add the TwoWayView:

    
    

    and finally, just declare it and deal with it like any regular ListView:

    TwoWayView lvTest = (TwoWayView) findViewById(R.id.lvItems);
    

    All the methods of ListView will work here as usual, but there is only one difference I noticed, which is when setting the choice mode, the method setChoiceMode not takes an int value but a value from enum called ChoiceMode, so list_view.setChoiceMode(ListView.CHOICE_MODE_SINGLE); will be lvTest.setChoiceMode(ChoiceMode.SINGLE); // or MULTIPLE or NONE.

提交回复
热议问题