반응형

RecyclerView #2 - 구분선 추가, 아이템간 간격 조절


RecyclerView #1- 구조및 기본 사용법

RecyclerView #2 - 구분선 추가, 아이템간 간격 조절

RecyclerView #3 - 컨텍스트 메뉴 처리

RecyclerView #4 - 아이템 클릭 처리

RecyclerView #5 - 아이템 선택 처리하기

RecyclerView #6 - ItemView를 클래스화 하기

RecyclerView #7 - ViewType 동적변경


RecyclerView.ItemDecoration


기본 구분선(DividerItemDecoration) 추가

 // 기본 구분선 추가
DividerItemDecoration dividerItemDecoration =
new DividerItemDecoration(recyclerView.getContext(),new LinearLayoutManager(this).getOrientation());
recyclerView.addItemDecoration(dividerItemDecoration);


아아템 사이의 간격 조절

RecyclerDecoration.java


package com.thirteenbrains.unodir.stdrecyclerview;

import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;

public class RecyclerDecoration extends RecyclerView.ItemDecoration {

private final int divHeight;


public RecyclerDecoration(int divHeight) {
this.divHeight = divHeight;
}

@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
if (parent.getChildAdapterPosition(view) != parent.getAdapter().getItemCount() - 1)

outRect.bottom = divHeight;

}
}

MainActivity.java

RecyclerDecoration spaceDecoration = new RecyclerDecoration(20);
recyclerView.addItemDecoration(spaceDecoration);


반응형

+ Recent posts