Android - ViewSwitcher no está cambiando vistas
-
04-10-2019 - |
Pregunta
Debe ser fácil, ¿verdad? Por lo tanto - así es como tengo ViewSwitcher
definido en XML (Id de diseños y omite por razones de brevedad)
<ViewSwitcher android:layout_height="wrap_content" android:layout_width="fill_parent" >
<!-- First view, comes up OK -->
<LinearLayout android:id="@+id/header1">
<!-- some more controls: Progress bar, test view and the button -->
</LinearLayout>
<!-- second view. changing to the actual (not include) layout has no effect -->
<include android:id="@+id/header2" />
</ViewSwitcher>
A continuación, en algún lugar de mi código de Java tengo este código
ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.profileSwitcher);
// more code that basically executes background search
// when call comes back - switch
switcher.bringToFront(); // does nothing
// switcher.bringChildToFront(findViewById(R.id.header2)); // no effect ether
Es que no es el cambio. Yo desarrollo de API v. 3 (1.5 +) y para mi sorpresa hay muy pocas referencias a ViewSwitcher. Me estoy perdiendo algo obvio aquí?
P.S. Me acabo de enterar por la fuerza bruta que esto funciona:
switcher.setDisplayedChild(1);
Aún así - ¿por qué no hubo suerte con bringToFront()
Solución
bringToFront()
realidad no tiene nada que ver con ViewSwitcher
, el método es heredado de vista de clase y es sinónimo de manipulación orden z de vista actual: https://developer.android.com/reference/android/view/View.html#bringToFront ()
Usted tiene que usar métodos showNext()
y showPrevious()
heredados de ViewAnimator
.
Otros consejos
En ViewSwitcher
para navegar entre las vistas se pueden utilizar los métodos showPrevious()
y showNext()
O uso también puede ir a la vista específica por el método setDisplayedChild(int index)
donde el índice puede ser 0
o 1