View pager for Android gallery effects multiple images

Source: Internet
Author: User

View pager for Android gallery effects multiple images

First, let's look at the following results:


From the above picture, we can see that when multiple images are added, they can be squashed into a gallery. We pull the images left and right to see the images we added. Is the effect much better? Let's see how it works!

The above effect is similar to the ViewPage effect in Android, but it is different from ViewPager. ViewPager can only display one image at a time.

In fact, we have used the clipChildren attribute of View. Here we want to set ViewPager and its parent form to false, as shown below:

Android: clipChildren = "false"

If the clipChildren attribute is set to true, it indicates that children is to be dropped to clip. That is to say, all parts beyond the current view will be dropped for the child element, set it to false here, which indicates that the part beyond the view is displayed. Do not cut it off.

Xml code:

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: id = "@ + id/viewpager"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: layout_marginLeft = "110dp"
Android: layout_marginRight = "110dp"
Android: clipChildren = "false">


Java code:

// 1. Set the number of cached items
MViewPager. setOffscreenPageLimit (3 );
// 2. Set the spacing between pages
MViewPager. setPageMargin (10 );
// 3. Distribute the touch events of the parent class to viewPgaer. Otherwise, only one view object in the middle can be moved.
Container. setOnTouchListener (new View. OnTouchListener (){
@ Override
Public boolean onTouch (View v, MotionEvent event ){
Return mViewPager. dispatchTouchEvent (event );
}
});




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.