|
|
@@ -1,7 +1,7 @@
|
|
|
package kr.co.zumo.app.lifeplus.view.screen.main.category;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
import android.graphics.Rect;
|
|
|
-import android.support.v7.widget.GridLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.view.View;
|
|
|
|
|
|
@@ -18,39 +18,33 @@ import kr.co.zumo.app.lifeplus.util.ResourceUtil;
|
|
|
* @since 2018-10-23
|
|
|
*/
|
|
|
public class GridItemDecoration extends RecyclerView.ItemDecoration {
|
|
|
- private int mHorizontalSpacing = ResourceUtil.dpToPx(9);
|
|
|
- private int mVerticalSpacing = ResourceUtil.dpToPx(9);
|
|
|
+
|
|
|
+ private static final int BANNER_VIEW_TYPE = 1;
|
|
|
+ private Context context;
|
|
|
+ private int itemOffset;
|
|
|
+
|
|
|
+ public GridItemDecoration(Context context, int itemOffset) {
|
|
|
+ this.context = context;
|
|
|
+ this.itemOffset = itemOffset;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
|
|
|
- {
|
|
|
+ public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
|
|
|
+ RecyclerView.State state) {
|
|
|
super.getItemOffsets(outRect, view, parent, state);
|
|
|
- // Only handle the vertical situation
|
|
|
- int position = parent.getChildPosition(view);
|
|
|
- if (parent.getLayoutManager() instanceof GridLayoutManager)
|
|
|
- {
|
|
|
- GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
|
|
|
- int spanCount, column;
|
|
|
- // Check the last item and is alone. Then set the parent's width
|
|
|
- if (position == parent.getAdapter().getItemCount() - 1 && position % 2 == 0)
|
|
|
- {
|
|
|
- spanCount = 1;
|
|
|
- outRect.left = mHorizontalSpacing;
|
|
|
- outRect.right = parent.getWidth() - mHorizontalSpacing;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- spanCount = layoutManager.getSpanCount();
|
|
|
- column = position % spanCount;
|
|
|
- outRect.left = mHorizontalSpacing * (spanCount - column) / spanCount;
|
|
|
- outRect.right = mHorizontalSpacing * (column + 1) / spanCount;
|
|
|
- }
|
|
|
-
|
|
|
- if (position < spanCount)
|
|
|
- {
|
|
|
- outRect.top = mVerticalSpacing;
|
|
|
- }
|
|
|
- outRect.bottom = mVerticalSpacing;
|
|
|
+
|
|
|
+ int position = parent.getChildAdapterPosition(view);
|
|
|
+ int itemViewType = parent.getAdapter().getItemViewType(position);
|
|
|
+ //배너일때
|
|
|
+ if (itemViewType == BANNER_VIEW_TYPE) {
|
|
|
+ outRect.left = itemOffset;
|
|
|
+ outRect.right = itemOffset;
|
|
|
+ outRect.top = ResourceUtil.dpToPx(35);
|
|
|
+ outRect.bottom = ResourceUtil.dpToPx(35);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ outRect.set(itemOffset, itemOffset, itemOffset, itemOffset);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|