StaggeredGridRecyclerView.java 文件源码

java
阅读 33 收藏 0 点赞 0 评论 0

项目:RecyclerViewAnimation 作者:
/**
 * 支持GridLayoutManager以及StaggeredGridLayoutManager
 *
 * @param child
 * @param params
 * @param index
 * @param count
 */
@Override
protected void attachLayoutAnimationParameters(View child, ViewGroup.LayoutParams params,
                                               int index, int count) {
    LayoutManager layoutManager = this.getLayoutManager();
    if (getAdapter() != null && (layoutManager instanceof GridLayoutManager
            || layoutManager instanceof StaggeredGridLayoutManager)) {

        GridLayoutAnimationController.AnimationParameters animationParams =
                (GridLayoutAnimationController.AnimationParameters) params.layoutAnimationParameters;

        if (animationParams == null) {
            animationParams = new GridLayoutAnimationController.AnimationParameters();
            params.layoutAnimationParameters = animationParams;
        }

        int columns = 0;
        if (layoutManager instanceof GridLayoutManager) {
            columns = ((GridLayoutManager) layoutManager).getSpanCount();
        } else {
            columns = ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
        }

        animationParams.count = count;
        animationParams.index = index;
        animationParams.columnsCount = columns;
        animationParams.rowsCount = count / columns;

        final int invertedIndex = count - 1 - index;
        animationParams.column = columns - 1 - (invertedIndex % columns);
        animationParams.row = animationParams.rowsCount - 1 - invertedIndex / columns;

    } else {
        super.attachLayoutAnimationParameters(child, params, index, count);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号