Android Gallery Effect Viewpager displays multiple pictures _android

Source: Internet
Author: User

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.

Related Article

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.