개발일지

삽질 - CoordinatorLayout, ViewPager 본문

삽질

삽질 - CoordinatorLayout, ViewPager

강태종 2021. 1. 26. 05:51

CoordinatorLayout에서 ViewPager를 사용할 경우 이상하게 작동하는 경우가 있다. (ex : ViewPager가 짤린다.)

AppBarLayout과 같이 사용시 @string/appbar_scrolling_view_behavior를 behavior로 설정하자.

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:background="@color/black"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.viewpager2.widget.ViewPager2
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.tabs.TabLayout
                app:tabIconTint="@color/white"
                app:tabIndicatorColor="@color/white"
                app:tabTextColor="@color/white"
                android:background="@color/black"
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </com.google.android.material.appbar.AppBarLayout>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

=> @string/appbar_scrolling_view_behavior는 Scroll이 가능한 View에 설정해야한다. (NestedScrollView, RecyclerView)

Comments