Let's look at it first.
is what we need to achieve, the function has the following three:
1. Gesture swipe can switch the interface, click on the boot one to boot four can also switch to the corresponding screen.
2. When you switch the interface, the horizontal line below the guide will move to the corresponding place.
3. When there is no gesture, the interface will rotate automatically, there is the effect of advertising rotation, the gesture is, will stop rotation.
The second function is implemented here.
Thought: To achieve this effect is actually very simple. On the one hand, we need to initialize the state of the cursor, first get the width of a textview, and then set the width of the imageview of the cursor to this size, to ensure textview and ImageView alignment. Then you need to listen to the Viewpager, whenever the viewpager occurs, set a translation animation to ImageView, so that it translates to the corresponding textview.
Initialize cursor State:
Private voidInitcursor () {cursor=(ImageView) Findviewbyid (r.id.cursor); Cursorwidth=Bitmapfactory.decoderesource (Getresources (), r.drawable.cursor). GetWidth (); Displaymetrics DM=NewDisplaymetrics (); Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM); intWindowWidth = Dm.widthpixels;//Get resolution width intTabwidth = windowwidth/listview.size ();
Will beThe cursor is set to the same width as the textview.
cursor.getlayoutparams (). Width=tabwidth; Cursorwidth=Tabwidth;
}
To set the listener for Viewpager:
We need to monitor the slide of the Viewpager, and then shift the cursor to the bottom according to the slide accordingly. Viewpager's Onpagechangelistener has been introduced in the previous article.
What we need here is the onpageselected (int arg0), which sets the translation animation of the cursor after the page has finished jumping.
...... Public void onpageselected (int arg0) { new translateanimation (cursorwidth* CurrentPage, Cursorwidth * arg0, 0, 0); Animation.setduration (+);
//refers to the end of the animation is the screen stays in this animation the last frame Animation.setfillafter (true); Cursor.startanimation (animation); = arg0; } ......
Once this is done, our functionality is realized.
Viewpager multiple page swipe toggle + cursor Swipe