Problem in TabLayout with ViewPager2 and Button

Viewed 55

I would appreciate your help to see if someone can tell me how to solve this problem with this behavior.

I have created a horizontal menu with tabs/fragment, in the TabLayout, where I show those fragment in ViewPager2. Each of those fragment of the menu, shows a text TextView, and the menu works correctly, if I click on any of the fragment it shows its content.

Well, there is a problem if I change the TextView for some <com.google.android.material.button.MaterialButton> buttons.

For example, I have 5 fragment in the menu, and in fragmet 3 that has the I change it to show a button, <com.google.android.material.button.MaterialButton>, if now I click to show fragment 4, it shows me the last fragment of the menu, fragment 5.

Fragmente 1, 2, 3, 4, 5, 6

 <ScrollView 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:id="@+id/fragmenMenu1"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:clickable="false"
     android:focusable="true"
   android:background="@color/Blanco"
     android:fillViewport="true"
     tools:context=".Menu3">
 
             <TextView
                 android:id="@+id/textViewMenu1"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:gravity="center"
                 android:text="1"
                 android:textSize="40sp" />
 </ScrollView>

Now I change the code of Fragment 3, for some buttons:

 <ScrollView 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:id="@+id/fragmenMenu1"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:clickable="false"
     android:focusable="true"
   android:background="@color/Blanco"
     android:fillViewport="true"
     tools:context=".Menu3">
         
             <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content">
         
                 <LinearLayout
                     android:id="@+id/linearL1"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
                     android:layout_margin="8dp"
                     android:gravity="center"
                     android:orientation="horizontal">
         
                     <com.google.android.material.button.MaterialButton
                         android:id="@+id/button1"
                         style="@style/Boton_difuminado_4"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_marginStart="8dp"
                         android:layout_marginEnd="8dp"
                         android:paddingStart="15dp"
                         android:paddingEnd="15dp"
                         android:text="Boton 1"
                         android:textAllCaps="false"
                         android:textColor="@android:color/white"
                         app:backgroundTint="@null"
                         app:backgroundTintMode="add" />
         
                     <com.google.android.material.button.MaterialButton
                         android:id="@+id/button2"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_marginStart="8dp"
                         android:layout_marginEnd="8dp"
                         android:backgroundTint="@color/Gris_1"
                         android:paddingStart="15dp"
                         android:paddingEnd="15dp"
                         android:text="Boton 2"
                         android:textAllCaps="false"
                         android:textColor="#ff0000"
                         android:textStyle="bold|italic"
                         app:backgroundTint="@null"
                         app:backgroundTintMode="add" />
         
                 </LinearLayout>
             </LinearLayout>
 </ScrollView>

Correct operation.

enter image description here

Incorrect operation.

enter image description here

What is going on here?

0 Answers
Related