Passing from a listview to a gridview

前端 未结 2 1693
小蘑菇
小蘑菇 2021-02-02 03:44

I have an activity with a list, whose items are made of an image+text. I need to allow the user to change the view and have a gridview instead of it (whose elements are still ma

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-02 04:16

    There are several ways you could achieve that.

    1. One solution is to have both the ListView and GridView stacked in a FrameLayout, and when you want to switch between these views, set the visibility GONE to one view and VISIBLE to another, then viceversa.

    2. Put both the ListView and GridView in a ViewFlipper

    3. Or, use a ViewSwitcher

    4. And finally, use just a GridView, but when you want to transition to a list view, set programmatically the number of columns to 1.

提交回复
热议问题