I\'m trying to use the ViewSwitcher to perform switches between two views. One is an ImageView and the other is a MapView. I have a button which the user clicks to perform t
Your ImageView tag should fall under ViewSwitcher tag, just like the com.google.android.maps.MapView.
Are you setting Layout parameters at runtime or is everything in the XML?
Have you tried wrapping the two views of the ViewSwitcher each into its own LinearLayout?
Add the ViewSwitcher widget to your xml layout file. to the ViewSwitcher add 2 new layouts.
<ViewSwitcher
android:id="@+id/viewSwitcher1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:inAnimation="@android:anim/slide_in_left" >
<LinearLayout
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/text"
android:text="This is simplezdscsdc text"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/text"
android:text="This issdsdsds simplezdscsdc text"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</ViewSwitcher>
In your activity, add function to a button which switches between the views
viewSwitcher = (ViewSwitcher)findViewById(R.id.viewSwitcher1);
myFirstView= findViewById(R.id.view1);
mySecondView = findViewById(R.id.view2);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (viewSwitcher.getCurrentView() != myFirstView){
viewSwitcher.showPrevious();
} else if (viewSwitcher.getCurrentView() != mySecondView){
viewSwitcher.showNext();
}
}
});
android:inAnimation="@android:anim/slide_in_left" allows the view to scroll in from the left
You need to have a LinearLayout wrapping everything else. On the example I see more than one but no main one.