如何制作RecyclerView网格"全高"?

时间:2015-11-18 16:02:20

标签: android gridview grid height android-recyclerview

在RecyclerView之前,我使用这个类来使网格的高度依赖于它的孩子(因此它在scrollview中工作正常):

public class FullHeightGridView extends GridView
{
    public FullHeightGridView(Context context)
    {
        super(context);
    }

    public FullHeightGridView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public FullHeightGridView(Context context, AttributeSet attrs,
                              int defStyle)
    {
        super(context, attrs, defStyle);
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        // Calculate entire height by providing a very large height hint.
        // View.MEASURED_SIZE_MASK represents the largest height possible.
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    }
}

如何修改GridLayoutManager以同样的方式运行?

0 个答案:

没有答案