android 区域交错,android - 自动调整交错GridLayoutManager - 堆栈内存溢出

但对于交错 GridLayoutManager。 我试图从这个很好的答案中编辑代码:

public class StaggeredGridAutofitLayoutManager extends StaggeredGridLayoutManager {

private int mColumnWidth;

private boolean mColumnWidthChanged = true;

public StaggeredGridAutofitLayoutManager(Context context, int columnWidth, int orientation) {

/* Initially set spanCount to 1, will be changed automatically later. */

super(1, orientation);

setColumnWidth(checkedColumnWidth(context, columnWidth));

}

private int checkedColumnWidth(Context context, int columnWidth) {

if (columnWidth <= 0) {

/* Set default columnWidth value (48dp here). It is better to move this constant

to static constant on top, but we need context to convert it to dp, so can't really

do so. */

columnWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48,

context.getResources().getDisplayMetrics());

}

return columnWidth;

}

public void setColumnWidth(int newColumnWidth) {

if (newColumnWidth > 0 && newColumnWidth != mColumnWidth) {

mColumnWidth = newColumnWidth;

mColumnWidthChanged = true;

}

}

@Override

public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {

if (mColumnWidthChanged && mColumnWidth > 0) {

int totalSpace;

if (getOrientation() == VERTICAL) {

totalSpace = getWidth() - getPaddingRight() - getPaddingLeft();

} else {

totalSpace = getHeight() - getPaddingTop() - getPaddingBottom();

}

int spanCount = Math.max(1, totalSpace / mColumnWidth);

setSpanCount(spanCount);

mColumnWidthChanged = false;

}

super.onLayoutChildren(recycler, state);

}

}

但是应用程序因以下错误而崩溃:

RecyclerView正在计算布局或滚动时无法调用此方法

(链接到line => setSpanCount(spanCount) );

有人可以帮助我进行此修改吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值