How to use ViewSwitcher in android for view animation
first create layout and put below code:-
<ViewSwitcher
android:id="@+id/viewSwitcher1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inAnimation="@android:anim/slide_in_left"
android:outAnimation="@android:anim/slide_out_right">
<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>
Code Behind code:-
for show first view use this code:-
first create layout and put below code:-
<ViewSwitcher
android:id="@+id/viewSwitcher1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inAnimation="@android:anim/slide_in_left"
android:outAnimation="@android:anim/slide_out_right">
<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>
Code Behind code:-
viewSwitcher = (ViewSwitcher)findViewById(R.id.viewSwitcher1);
myFirstView= findViewById(R.id.view1);
mySecondView = findViewById(R.id.view2);
if (viewSwitcher.getCurrentView() != myFirstView)
viewSwitcher.showPrevious();
for show second view use this code:-
if (viewSwitcher.getCurrentView() != mySecondView)
viewSwitcher.showNext();
where we write these code...."viewswither.shownext()" and viewswither.showprevious()
ReplyDeleteDo you know how to invert animations without code (From XML)?
ReplyDelete