package com.bxzk.afxj.other;

import android.graphics.Rect;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.bxzk.afxj.application.BApplication;
import com.bxzk.afxj.util.DensityUtil;


/*
* LinearLayoutManager设置Item间距的的一个辅助类
* */
public class SpacesItemDecoration4 extends RecyclerView.ItemDecoration {
    private int space;




    public SpacesItemDecoration4(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
        outRect.bottom = space ;
        outRect.right = DensityUtil.dip2px(BApplication.getContext(), 10f);
        /*DisplayMetrics dm = BApplication.getContext().getResources().getDisplayMetrics();
        int w = dm.widthPixels; //获取当前界面的宽度
        int i = DensityUtil.dip2px(BApplication.getContext(), 38f);
        LinearLayout ll = (LinearLayout) view;
        View childAt = ll.getChildAt(0);
        int width = childAt.getLayoutParams().width;
        int gap = (w-i - 6 * width)/5;
        if(parent.getChildAdapterPosition(view)%6  ==  0) {
            outRect.left = 0;
            outRect.right = 0;
        }else if(parent.getChildAdapterPosition(view) %5 ==  0) {
            outRect.right = 0;
            outRect.left = 0;
        }else {
            outRect.left =0;
            outRect.right =gap;
        }*/
        /*outRect.left = space;
        outRect.right = space;
        outRect.bottom = space;

        if (parent.getChildLayoutPosition(view) == 0) {
            outRect.top = space;
        } else {
            outRect.top = 0;
        }*/

        // Add top margin only for the first item to avoid double space between items

    }
}
