TabLayout внутри CardView - нажатие на вкладки не работает, но смахивание фрагментов в ViewPager работает - PullRequest
0 голосов
/ 23 апреля 2020

Я использую TabLayout с ViewPager внутри CardView. Я настроил ViewPager для работы с TabLayout и двумя фрагментами. Но как-то смахивание работает, но нажатие на вкладки не работает. Оба будут работать нормально, если я переместу ViewPager за пределы CardView.

Ниже приведен мой XML макет -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/bg_app_color_gradient"
    tools:context=".View.LoginActivity">

    <androidx.cardview.widget.CardView android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin128dp"
        android:layout_marginStart="@dimen/margin32dp"
        android:layout_marginEnd="@dimen/margin32dp"
        android:layout_marginBottom="@dimen/margin32dp"
        app:cardCornerRadius="10dp"
        app:cardElevation="5dp"
        app:cardPreventCornerOverlap="false">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/margin64dp"
            android:layout_marginEnd="@dimen/margin64dp"
            android:layout_marginBottom="@dimen/margin32dp"
            android:layout_marginTop="@dimen/margin48dp"
            android:clipToPadding="false">

            <View
                android:id="@+id/indicator"
                android:layout_width="0dp"
                android:layout_height="50dp"
                android:background="@drawable/gradient_bg"/>

            <com.google.android.material.tabs.TabLayout
                android:id="@+id/tab"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/tab_bg"
                app:tabGravity="fill"
                app:tabMode="fixed"
                app:tabSelectedTextColor="@color/appSecondaryWhiteColor"
                app:tabIndicatorColor="@null"
                app:tabRippleColor="@null"/>

        </FrameLayout>

        <androidx.viewpager.widget.ViewPager
            android:id="@+id/viewPager"
            android:overScrollMode="never"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </androidx.cardview.widget.CardView>
</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...