Estoy tratando de usar el ViewSwitcher para realizar cambios entre dos vistas. Uno es un ImageView y el otro es un MapView. Tengo un botón en el que el usuario hace clic para realizar este cambio, pero mis códigos están causando un error. ¿Tienen alguna idea de qué va esto?¿Cómo usar Android ViewSwitcher?
<?xml version="1.0" encoding="utf-8"?>
<linearlayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<relativelayout
android:id="@+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<imageview
android:id="@+id/banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignparenttop="true"
android:background="@drawable/banner_location"
android:clickable="false">
</imageview>
<linearlayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/banner"
android:layout_centerhorizontal="true"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:paddingbottom="5px">
<imagebutton
android:id="@+id/btnBusSvcs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginright="5px"
android:layout_margintop="5px"
android:background="@drawable/btn_bus_svcs">
</imagebutton>
<imagebutton
android:id="@+id/btnDrvRoute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginleft="5px"
android:layout_margintop="5px"
android:background="@drawable/btn_drv_route">
</imagebutton>
</linearlayout>
<viewswitcher
android:id="@+id/switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/imgViewBusSvcs"
android:layout_below="@+id/LinearLayout01">
<imageview
android:id="@+id/imgViewBusSvcs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/LinearLayout01"
android:layout_centerinparent="true"
android:layout_gravity="center_horizontal"
android:background="@drawable/bus_svcs"
android:clickable="false">
</imageview>
<com.google.android.maps.mapview
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="300px"
android:apikey="REMOVE MY API KEY"
android:clickable="true">
</com.google.android.maps.mapview>
</viewswitcher>
<imagebutton
android:id="@+id/btnBackHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignparentbottom="true"
android:layout_centerhorizontal="true"
android:layout_gravity="center_horizontal"
android:background="@drawable/btn_back_to_home">
</imagebutton>
</relativelayout>
</linearlayout>
El error es como tal
11-05 20:53:13.964: ERROR/AndroidRuntime(1417): Uncaught handler: thread main exiting due to uncaught exception
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.widget.RelativeLayout.getRelatedView(RelativeLayout.java:694)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.widget.RelativeLayout.getRelatedViewParams(RelativeLayout.java:708)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.widget.RelativeLayout.applySizeRules(RelativeLayout.java:629)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:279)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.view.View.measure(View.java:7115)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2875)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.widget.LinearLayout.measureVertical(LinearLayout.java:350)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.view.View.measure(View.java:7115)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2875)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.view.View.measure(View.java:7115)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2875)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.view.View.measure(View.java:7115)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.view.ViewRoot.performTraversals(ViewRoot.java:698)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.os.Looper.loop(Looper.java:123)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at android.app.ActivityThread.main(ActivityThread.java:3948)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at java.lang.reflect.Method.invoke(Method.java:521)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
11-05 20:53:13.995: ERROR/AndroidRuntime(1417): at dalvik.system.NativeStart.main(Native Method)
apreciar realmente la ayuda! :)
Hola, gracias. He vuelto a publicar los códigos XML. – fgs
lol, se olvidó abt it. ¡Gracias! – fgs
¿Ha intentado envolver las dos vistas del ViewSwitcher cada una en su propia LinearLayout? –