elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Problema en TabLayout con ViewPager2
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problema en TabLayout con ViewPager2  (Leído 3,370 veces)
MaX2

Desconectado Desconectado

Mensajes: 116


Ver Perfil
Problema en TabLayout con ViewPager2
« en: 28 Enero 2022, 21:58 pm »

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

Código
  1. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:app="http://schemas.android.com/apk/res-auto"
  3.     xmlns:tools="http://schemas.android.com/tools"
  4.     android:id="@+id/fragmenMenu1"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:clickable="false"
  8.     android:focusable="true"
  9.   android:background="@color/Blanco"
  10.     android:fillViewport="true"
  11.     tools:context=".Menu3">
  12.  
  13.             <TextView
  14.                 android:id="@+id/textViewMenu1"
  15.                 android:layout_width="match_parent"
  16.                 android:layout_height="wrap_content"
  17.                 android:gravity="center"
  18.                 android:text="1"
  19.                 android:textSize="40sp" />
  20. </ScrollView>
  21.  

Ahora cambio el código del Fragment 3, por unos botones:

Código
  1. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:app="http://schemas.android.com/apk/res-auto"
  3.     xmlns:tools="http://schemas.android.com/tools"
  4.     android:id="@+id/fragmenMenu1"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:clickable="false"
  8.     android:focusable="true"
  9.   android:background="@color/Blanco"
  10.     android:fillViewport="true"
  11.     tools:context=".Menu3">
  12.  
  13.             <LinearLayout
  14.                 android:layout_width="match_parent"
  15.                 android:layout_height="wrap_content">
  16.  
  17.                 <LinearLayout
  18.                     android:id="@+id/linearL1"
  19.                     android:layout_width="match_parent"
  20.                     android:layout_height="match_parent"
  21.                     android:layout_margin="8dp"
  22.                     android:gravity="center"
  23.                     android:orientation="horizontal">
  24.  
  25.                     <com.google.android.material.button.MaterialButton
  26.                         android:id="@+id/button1"
  27.                         style="@style/Boton_difuminado_4"
  28.                         android:layout_width="wrap_content"
  29.                         android:layout_height="wrap_content"
  30.                         android:layout_marginStart="8dp"
  31.                         android:layout_marginEnd="8dp"
  32.                         android:paddingStart="15dp"
  33.                         android:paddingEnd="15dp"
  34.                         android:text="Boton 1"
  35.                         android:textAllCaps="false"
  36.                         android:textColor="@android:color/white"
  37.                         app:backgroundTint="@null"
  38.                         app:backgroundTintMode="add" />
  39.  
  40.                     <com.google.android.material.button.MaterialButton
  41.                         android:id="@+id/button2"
  42.                         android:layout_width="wrap_content"
  43.                         android:layout_height="wrap_content"
  44.                         android:layout_marginStart="8dp"
  45.                         android:layout_marginEnd="8dp"
  46.                         android:backgroundTint="@color/Gris_1"
  47.                         android:paddingStart="15dp"
  48.                         android:paddingEnd="15dp"
  49.                         android:text="Boton 2"
  50.                         android:textAllCaps="false"
  51.                         android:textColor="#ff0000"
  52.                         android:textStyle="bold|italic"
  53.                         app:backgroundTint="@null"
  54.                         app:backgroundTintMode="add" />
  55.  
  56.                 </LinearLayout>
  57.             </LinearLayout>
  58. </ScrollView>
  59.  

Trabajando bien


Trabajando mal



¿Qué es lo que esta pasando aquí?

Un saludo.



En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines