I would like to switch to certain views in a ViewFlipper. Currently, I have 6 children inside the ViewFlipper. And I am having some buttons for navigation. It is very much similar to "News and weather" application.
ViewFlipper in android is an extension of ViewAnimator class, which animates between two or more views that have been added to it. Only one child is shown at a time and the user can flip to view the other child views.
Flipper is a platform for debugging iOS, Android and React Native apps. Visualize, inspect, and control your apps from a simple desktop interface. Use Flipper as is or extend it using the plugin API.
See this simple complete example of android.widget.ViewFlipper. With it you can create different layout from xml and then switch among them with simple method like this:
ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.myViewFlipper); // you can switch between next and previous layout and display it viewFlipper.showNext(); viewFlipper.showPrevious(); // or you can switch selecting the layout that you want to display viewFlipper.setDisplayedChild(1); viewFlipper.setDisplayedChild(viewFlipper.indexOfChild(findViewById(R.id.secondLayout)
Xml example with tree layouts:
<ViewFlipper android:id="@+id/myViewFlipper" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/firstLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > [...] </LinearLayout> <LinearLayout android:id="@+id/secondLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > [...] </LinearLayout> <LinearLayout android:id="@+id/thirdLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > [...] </LinearLayout> </ViewFlipper>
Call setDisplayedChild()
, passing the 0
-based index of the child View
you want to display.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With