Hola buenas tardes, agradecería vuestra ayuda a ver si alguien me puede decir cómo solucionar este problema con este comportamiento.
Tengo creado un menú horizontal con pestañas/fragment, en el TabLayout, donde muestro esos fragment en ViewPager2.
Cada uno de esos fragment del menú, muestra un texto
<TextView>, y el menú funciona correctamente, si pulso en cualquiera de los fragment muestra su contenido.
Pues bien, hay un problema si cambio el
<TextView> por unos botones
<com.google.android.material.button.MaterialButton>.
Por ejemplo, tengo 5 fragment en el menú, y en el fragmet 3 que tiene el <TextView> lo cambio para mostrar un botón, <com.google.android.material.button.MaterialButton>, si ahora pulso para mostrar el fragment 4, me muestra el ultimo fragment del menú, el fragment 5.
Fragment 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>
Ahora cambio el código del Fragment 3, por unos botones:
<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>
Trabajando bien
(https://i.imgur.com/aShYko9.gif)
Trabajando mal
(https://i.imgur.com/I1MnyP9.gif)
¿Qué es lo que esta pasando aquí?
Un saludo.