First look at the Viewpager display multiple picture effects:
From the above picture can be seen, when adding more than a picture, can be formed below the effect of a gallery, we pull around the picture to see we add in the picture, the effect is not a lot better? Let's see how to achieve it!
The above effect is similar to the viewpage effect of Android, but unlike Viewpager, Viewpager can only display one picture at a time.
We're actually using the Clipchildren property of the view, where we're going to set the Viewpager and its parent form to false, as follows:
Android:clipchildren= "false"
Because if the Clipchildren property is set to true, it means that we are going to give the children to clip, that is, for the child element, the part that is out of the current view will be cut off, so we set it to false here, indicating that it is beyond the view and not cut off , still shown.
XML Code section:
<!--Configure the Clipchildren=false of container and pager, and specify marginleft and MarginRight values-->
Android:id= "@+id/container"
android:layout_width= "match_parent"
android:layout_height= "100DP"
Android:clipchildren= "false"
android:gravity= "center_horizontal"
android:layertype= "Software"
android:orientation= "Horizontal" >
<android.support.v4.view.viewpager
android:id= "@+id/viewpager "
android:layout_width=" match_parent "
android:layout_height=" match_parent "
android:layout_ marginleft= "110DP"
android:layout_marginright= "110DP"
android:clipchildren= "false" >
</ Android.support.v4.view.viewpager>
</LinearLayout>
Java Code section:
1. Set the cache number of the behind-the-scenes item
mviewpager.setoffscreenpagelimit (3);
2. Set the spacing between pages and
Mviewpager.setpagemargin (a);
3. Distribute the touch events of the parent class to the Viewpgaer, otherwise you can only slide one View object in the middle
container.setontouchlistener (new View.ontouchlistener () {
@Override Public
Boolean Ontouch (View v., motionevent event) {return
mviewpager.dispatchtouchevent (event);
}
});
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.