GridLayout Column width

前端 未结 6 1988
再見小時候
再見小時候 2021-02-11 12:27

I have 2 columns in my GridLayout. What I want to do is make those columns take up half of the width of the screen each and then have its child contents fill their

6条回答
  •  我在风中等你
    2021-02-11 13:08

    When you use a GridLayoutManager you are able to use setSpanSizeLookup. Here is a snippet from my project which should help to use this method properly:

    if (mAdapter == null) {
        final int columnCount = getResources().getInteger(R.integer.numberGridColumns);
        mLayoutManager = new GridLayoutManager(getActivity(), columnCount);
        mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                switch (mAdapter.getItemViewType(position)) {
                    case ListAdapter.VIEW_TYPE_ONE_COLUMN:
                        return columnCount;
                    case RecipeListAdapter.VIEW_TYPE_FULL_COLUMN:
                    default:
                        return 1;
                }
            }
        });
        mRecyclerView.setLayoutManager(mLayoutManager);
    
        mAdapter = new RecipeListAdapter(mPresenter);
        mRecyclerView.setAdapter(mAdapter);
    }
    mAdapter.notifyDataSetChanged();
    

提交回复
热议问题