【问题标题】:How do i convert Grid View in List View inside fragment?如何在片段内的列表视图中转换网格视图?
【发布时间】:2017-06-20 05:18:35
【问题描述】:

This is what I am trying to build

我不知道如何使用 ImageButtontabs 来做到这一点。我可以在运行时更改片段的布局吗?还是我应该使用 2 个不同的片段?

【问题讨论】:

  • 这是您在屏幕截图中查看的卡片视图和回收站视图。在 google 上搜索 card view 和 recycler view,你会发现很多教程来实现这一点。

标签: android listview gridview fragment


【解决方案1】:

您必须使用RecyclerView 并将其布局管理器设置为listView。使用LinearLayoutManager,对于网格视图,您必须使用GridLayoutManager

    RecyclerView recyclerview = (RecyclerView) findViewById(R.id.recyclerview);


    //this is for list view
    //    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);

     //this is fro grid view
        GridLayoutManager mLayoutManager = new GridLayoutManager(this, 2);

    recyclerview.setLayoutManager(mLayoutManager);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多