如何解决MIUI Global 9.6 上带有 GridLayoutManager 的 RecyclerView 错误 |稳定版 9.6.30 (LHMMFID) Android L
我为我的动画 Gridlayout 使用了自定义 RecyclerView,它在其他设备上运行良好。不幸的是,当我在 Redmi Note 2 上对其进行测试时,我遇到了一个奇怪的错误,其中第一行项目无法正确显示,因为有一个巨大的空间,就像屏幕截图上的一样
我注意到这是因为添加 android:requiresFadingEdge="vertical"
这是自定义的 RecyclerView 类
public class GridRecyclerView extends RecyclerView {
public GridRecyclerView(Context context) {
super(context);
}
public GridRecyclerView(Context context,AttributeSet attrs) {
super(context,attrs);
}
public GridRecyclerView(Context context,AttributeSet attrs,int defStyle) {
super(context,attrs,defStyle);
}
@Override
protected void attachLayoutAnimationParameters(View child,ViewGroup.LayoutParams params,int index,int count) {
final LayoutManager layoutManager = getLayoutManager();
if (getAdapter() != null && layoutManager instanceof GridLayoutManager) {
GridLayoutAnimationController.AnimationParameters animationParams =
(GridLayoutAnimationController.AnimationParameters) params.layoutAnimationParameters;
if (animationParams == null) {
// If there are no animation parameters,create new once and attach them to
// the LayoutParams.
animationParams = new GridLayoutAnimationController.AnimationParameters();
params.layoutAnimationParameters = animationParams;
}
// Next we are updating the parameters
// Set the number of items in the RecyclerView and the index of this item
animationParams.count = count;
animationParams.index = index;
// Calculate the number of columns and rows in the grid
final int columns = ((GridLayoutManager) layoutManager).getSpanCount();
animationParams.columnsCount = columns;
animationParams.rowsCount = count / columns;
// Calculate the column/row position in the grid
final int invertedIndex = count - 1 - index;
animationParams.column = columns - 1 - (invertedIndex % columns);
animationParams.row = animationParams.rowsCount - 1 - invertedIndex / columns;
} else {
// Proceed as normal if using another type of LayoutManager
super.attachLayoutAnimationParameters(child,params,index,count);
}
}
}
对于整个代码,您可以从这个博客中获得 https://proandroiddev.com/enter-animation-using-recyclerview-and-layoutanimation-part-2-grids-688829b1d29b
有人知道这个问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。