Android Gallery Effect Viewpager display multiple images

Source: Internet
Author: User

First look at the following effect:


from the picture above you can see that when you add more than one picture, you can create a Gallery the effect, We pull the picture around to see what we add to the picture, the effect is not much better? Let's see how it's going to come true!

The above effect is similar to the ViewPage effect in Android, but unlike Viewpager,Viewpager can only display one picture at a time .

In fact, we are using the Clipchildren property of the view, where we want 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 indicates that we are going to clip the children, which means that for the child element, the part that is outside the current view is cut off, so we set it to false here, which means that the part of the view is beyond the point, not cut off , is still displayed.

XML Code section:

<!--Configure Clipchildren=false for container and pager, and specify values for MarginLeft and MarginRight-   

<linearlayout
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 count for behind-the-scenes item Mesh
Mviewpager.setoffscreenpagelimit (3);
//2. Set the spacing between pages
Mviewpager. Setpagemargin (10);
//3. Distribute the touch events of the parent class to Viewpgaer, or you can slide only one of the middle view objects
Container.setontouchlistener (New View.ontouchlistener () {
@Override
public boolean OnTouch (View V, motionevent event) {
Return Mviewpager.dispatchtouchevent (event);
}
});




Android Gallery Effect Viewpager display multiple images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.