recyclerview is not fit for all screen sizes

前端 未结 2 1296
别跟我提以往
别跟我提以往 2020-11-30 14:44

I am using recylerview and gridlayout manager with cardviews for each row, my row view(childview) is not responsive at all.

I want to show 15 cardviews in such a wa

2条回答
  •  误落风尘
    2020-11-30 15:19

    you can use this:

    recyclerView.setLayoutManager(new RecyclerView.GridLayoutManager(this, span_count)

    You could have a res/values/ints.xml file with elements, giving the integer a name (name attribute) and value (text of the node). You could also have res/values-w600dp/ints.xml or res/values-land or other variations of the resource, where you provide different values to use for different screen sizes. Then, at runtime, call getResources().getInteger() to retrieve the correct value of the resource to use for the current device, and use that in your GridLayoutManager constructor. Now, you are in control over how many columns there are, by controlling how many spans are supplied to the constructor.

    https://developer.android.com/training/multiscreen/screensizes

    Another approach, suggested by Chiu-Ki Chan, is to create a subclass of RecyclerView, on which you provide a custom attribute for a desired approximate column width. Then, in your subclass’ onMeasure() method, you can calculate the number of spans to use to give you the desired column width.

    https://developer.android.com/reference/android/support/v7/widget/GridLayoutManager.html#GridLayoutManager(android.content.Context,%20int)

    https://developer.android.com/reference/android/support/v7/widget/RecyclerView#setlayoutmanager

提交回复
热议问题