Viewpager Overview:
Layout Manager that allows the user-to-flip left and right through pages of data. You supply an implementation of a pageradapter to generate the pages of the view shows.
Note This class is currently under early design and development. The API would likely change in later updates of the compatibility library, requiring changes to the source code of apps whe N They is compiled against the newer version.
Viewpager is very often used in conjunction with Android.app.Fragment, which is a convenient-to supply and manage the Lifecycle of each page. There is standard adapters implemented for using fragments with the Viewpager, which cover the most common use cases. These is android.support.v4.app.FragmentPagerAdapter and android.support.v4.app.FragmentStatePagerAdapter; Each of these classes has simple code showing how to build a full user interface with them.
Here are a more complicated example of Viewpager, using the IT in conjuction with Android.app.ActionBar tabs. You can find other examples of using Viewpager in the API 4+ support Demos and APIs 13+ support Demos sample code.
{@sample Development/samples/support13demos/src/com/example/android/supportv13/app/actionbartabspager.java Complete
The layout Manager allows users to browse data pages by swiping left and right. Developers need to provide the data adapters that generate these pages---implement Pageradapter.
It is worth noting that the Viewpager class is still in the pre-design and development phase, it is possible to update in future compatibility packs, if Viewpager at compile time and update version conflict, it needs to modify its source code.
Viewpager is often used in conjunction with fragment, which makes it easy and effective to manage the life cycle of each page. In order for fragment and Viewpager to be used together, Standard adapters with the most common use cases are already available: Fragmentpageradapter and Fragmentstatepageradapter. The two classes are subclasses of Pageradapter, and there are some simple code to show how they can be used to create a complete user interface.
Viewpager has a more complex example of using it with Actionbar tab. Additional and Viewpager-related examples can be found in the sample code for the V4 and V13 support libraries. (Path: Development/samples/support13demos/src/com/example/android/supportv13/app/actionbartabspager.java)
Support13demos Source Download: http://download.csdn.net/detail/dongdong230/8440129
Support13demos Source Download: http://download.csdn.net/detail/dongdong230/8440129
Viewpager Method Highlights:1.Viewpager inherits ViewGroup and needs to rewrite its abstract methodOnLayout:
protected void OnLayout (boolean changed, int l, int t, int r, int b)
Call scenario: Called when a view is set to its child's size and position. Child view, including children, must override the OnLayout (boolean, int, int, int, int) methods and invoke the respective layout (int, int, int, int) methods
The meaning of several parameters:
| Changed |
View has a new size or position |
| L |
Left position relative to parent view |
| T |
Top position relative to Parent view |
| R |
Right position relative to parent view |
| B |
The bottom location relative to the parent view |
Here, decor view and non-decor view are moved in position, based on srollx and offset.
Internal classes for 2.ViewPager:Layoutparams:
Layout parameters that should is supplied for the added to a viewpager.
This is the layout parameter class that is prepared for the Viewpager page child view.
Several of these important fields:
| isdecor |
for decor View only, the location of the layout child view, the constant value in android.view.Gravity |
| widthfactor |
|
| needsmeasure |
true: The view is added at positive layout and needs to be measured before the view is laid out |
| position |
|
3.ViewPager Important InterfaceOnpagechangelistener:
Three non-implemented methods: Onpagescrolled, onpageselected, onpagescrollstatechanged
The most common interface, no need to say more.
There is also an inner class Simpleonpagechangelistener: Implements the Onpagechangelistener method, but does not write implementation code, if you do not want to rewrite Onpagechangelistener all methods, use this inner class.
4. Slide the Animation interface:Pagetransformer: The animated effect when the page slides
Transformpage: Adding sliding animations to a specified page
5. Other methods
- Addfocusables: currently displayed page to get focus
- Addtouchables: currently displayed page to get touch events
- AddView: Add child view according to specified layout parameters
- Arrowscroll: The direction of the slide?
- Beginfakedrag: Start control of slide events, Viewpager ignores touch events while in fake drag
- Canscrollhorizontally: Determines whether the view can slide horizontally in the specified direction (derection). Derection: Negative numbers represent left, positive numbers represent right
- Computescroll: Called by the parent class to calculate the distance that its subclasses should slide
- Dispatchkeyevent: Distributing key events
- Dispatchpopulateaccessibilityevent: Distributes the secondary event to view, and then adds the text content of its subclass to this event.
- Draw: Draws the view and its child view onto the canvas.
- Endfakedrag: End Control Slide Event
- Executekeyevent: Executing key event
"Android interface Effect 45" Viewpager Source Analysis