RecyclerView에 대한 사용자 지정 LayoutManager 및 ItemDecoration

중요

이 문서에서 설명하는 기능 및 지침은 공개 미리 보기 상태이며 일반적으로 공급되기 전에 대대적으로 수정될 수 있습니다. Microsoft는 여기에 제공된 정보에 대해 명시적 또는 묵시적 보증을 하지 않습니다.

FoldableLayoutManagerLinearLayoutManager 또는 GridLayoutManager에 대한 래퍼로, 앱이 디스플레이에 걸쳐 확장되는지에 따라 둘 중 하나를 제공합니다.

FoldableItemDecoration은 앱이 스팬되고 FoldableLayoutManager가 사용되는 경우 힌지(있는 경우)로 가려지지 않도록 두 열 사이에 여백을 만드는 RecyclerView.ItemDecoration의 구현입니다.

단일 화면에서 FoldableLayoutManagerFoldableItemDecoration를 사용하는 RecyclerView는 평소와 같이 표시됩니다.

Surface Duo Emulator displaying an application on the left screen with items of the same size

스팬 모드에서 FoldableLayoutManagerFoldableItemDecoration를 사용하는 RecyclerView는 콘텐츠를 두 화면으로 분할합니다.

Surface Duo Emulator displaying a spanned application with items of the same size

1.0.0-beta4 버전부터 FoldableLayoutManagerFoldableItemDecoration를 사용하는 RecyclerView는 폴더블 디바이스에도 FoldingFeature에 걸쳐 콘텐츠를 분할합니다. 예를 들어 6.7" 수평 접이식 에뮬레이터에서는 다음과 같이 표시됩니다.

Foldable Emulator displaying an application on the whole screen with items of the same size

class MainActivity : AppCompatActivity() {
//...
    
    private fun onWindowLayoutInfoChanged(windowLayoutInfo: WindowLayoutInfo) {
        recyclerView.layoutManager = FoldableLayoutManager(this, windowLayoutInfo).get()
        recyclerView.replaceItemDecorationAt(FoldableItemDecoration(windowLayoutInfo))
    }
}

FoldableStaggeredLayoutManager 및 FoldableStaggeredItemDecoration

FoldableStaggeredItemDecoration와 함께 사용해야 하는 FoldableStaggeredLayoutManager를 포함하여 이중 화면 모드에서 StaggeredGridLayoutManager를 사용하는 방법도 있습니다.

단일 화면에서 FoldableStaggeredLayoutManagerFoldableStaggeredItemDecoration를 사용하는 RecyclerView는 평소와 같이 표시됩니다.

Surface Duo Emulator displaying an application on the left screen with items of variable sizes

스팬 모드에서 FoldableStaggeredLayoutManagerFoldableStaggeredItemDecoration를 사용하는 RecyclerView는 콘텐츠를 두 화면으로 분할합니다.

Surface Duo Emulator displaying a spanned application with items of variable sizes

1.0.0-beta4 버전부터 FoldableStaggeredLayoutManagerFoldableStaggeredItemDecoration를 사용하는 RecyclerView는 폴더블 디바이스에도 두 화면 간에 콘텐츠를 분할합니다. 예를 들어 6.7" 수평 접이식 에뮬레이터에서는 다음과 같이 표시됩니다.

Foldable Emulator displaying an application on the whole screen with items of variable sizes

class MainActivity : AppCompatActivity() {
//...
    
    private fun onWindowLayoutInfoChanged(windowLayoutInfo: WindowLayoutInfo) {
        recyclerView.layoutManager = FoldableStaggeredLayoutManager(this, windowLayoutInfo).get()
        recyclerView.replaceItemDecorationAt(FoldableStaggeredItemDecoration(windowLayoutInfo))
    }
}