package com.bxzk.afxj.other;

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

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


/*
* LinearLayoutManager设置Item间距的的一个辅助类
* */
public class SpacesItemDecoration5 extends RecyclerView.ItemDecoration {


    public SpacesItemDecoration5() {
    }



    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {

        DisplayMetrics dm = BApplication.getContext().getResources().getDisplayMetrics();
        int screenWidth = dm.widthPixels;
        int paddingWidth  = DensityUtil.dip2px(BApplication.getContext(), 47f);
        int column = 2;
        int viewTotalWidht =  DensityUtil.dip2px(BApplication.getContext(), 150f)*column ;
        int spaceWidth = (screenWidth - paddingWidth - viewTotalWidht)/(column * (column - 1));

        if(parent.getChildAdapterPosition(view)%2  ==  0) {
            outRect.left = 0;
            outRect.right = spaceWidth/2;

        }else {
            outRect.right = 0;
            outRect.left = spaceWidth/2;

        }
        outRect.bottom = DensityUtil.dip2px(BApplication.getContext(), 20f);

        /*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

    }
}
