我正在尝试覆盖GridLayoutManager中的measureChild,以便在测量中使用特定的布局参数。但是GridLayoutManager有它自己的measureChild私有实现
private void measureChild(View view, int otherDirParentSpecMode, boolean alreadyMeasured)如果我在RecyclerView.LayoutManager中重写公共measureChild
@Override
public void measureChild(View child, int widthUsed, int heightUsed) {
super.measureChild(child, widthUsed, heightUsed);
}它将永远不会被调用。
是否可以在GridLayoutManager中测量儿童
发布于 2017-04-24 15:25:12
这两个方法有不同的签名,所以覆盖它们应该不会有任何问题。根据您为子类中的函数指定的参数,将调用相应的超级函数。
但是,您需要修改从GridLayoutManager扩展的子类,以覆盖所有使用GridLayoutmanager管理器的measureChild实现的函数,以便能够使用其他实现。
要检查哪些方法在GridLayoutManager中调用measureChild,可以查看source
编辑:似乎从LinearLayoutManager派生的layoutChunk方法是包私有的,所以在这种情况下,我认为唯一的方法是扩展RecyclerView.LayoutManager并复制GridLayoutManager的整个代码,用您自己的替换替换measureChild调用,适当地修改代码
https://stackoverflow.com/questions/43581744
复制相似问题