안녕세계
[안드로이드] RecyclerView - Item 간격 본문
[안드로이드] RecyclerView - Item 간격
Junhong Kim 2017. 8. 3. 13:47728x90
반응형
[Step1] ItemDecoration 정의
public class RecyclerViewDecoration extends RecyclerView.ItemDecoration {
private final int divHeight;
public RecyclerViewDecoration(int divHeight) {
this.divHeight = divHeight;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
outRect.top = divHeight;
}
}
[Step2] 사용
private void initRecyclerView(ArrayList<CultureSpaceItem> items) {
recyclerView.setHasFixedSize(true);
LinearLayoutManager lm = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(lm);
mAdapter = new RecyclerViewAdapter(getActivity(), items);
recyclerView.setAdapter(mAdapter);
recyclerView.addItemDecoration(new RecyclerViewDecoration(25));
}
※ 참고
[1] http://gogorchg.tistory.com/entry/Android-Recycler-View-%EC%82%AC%EC%9D%B4%EC%97%90-divider-%ED%81%AC%EA%B8%B0-%EC%A1%B0%EC%A0%88
728x90
반응형
'Client > Android' 카테고리의 다른 글
[안드로이드] 다른 Activity Method 호출 (0) | 2017.08.07 |
---|---|
[안드로이드] Fragment - 메뉴 설정 (수정 필요) (0) | 2017.08.04 |
[안드로이드] Custom - Dialog (3) | 2017.08.02 |
[안드로이드] VersionName & VersionCode (0) | 2017.08.01 |
[안드로이드] ImageView에 image url로 이미지 지정 (0) | 2017.06.13 |
Comments