As can be seen from the above figure, when adding multiple pictures, the gallery effect can be formed below. Let's pull the picture left and right to see the picture we added. Is the effect much better? Let's take a look at how to achieve it!
The above effect is similar to ViewPage in Android, but unlike ViewPager, ViewPager can only display one picture at a time.
In fact, we use the clipChildren property of View, and we want to set ViewPager and its parent form to false here, as shown below:
android:clipChildren="false "
Because if the clipChildren property is set to true, it means that we have to crop out the sub-elements, that is, for the sub-elements, the part beyond the current view will be cut off, so we set it to false here, that is, the part beyond the view will still be displayed without being cut off.
Xml code part:
& lt! -configure clipChildren=false for containers and pagers, and specify the values of marginLeft and Marginright->;
& lt linear layout
android:id="@+id/container "
Android:layout _ width = " match _ parent "
Android:layout _ height = " 100 DP "
android:clipChildren="false "
Android:gravity = " center _ horizontal "
Android:layerType= "software"
Android:orientation = " horizontal " & gt;
& ltAndroid . support . v4 . view . view pager
android:id="@+id/viewpager "
Android:layout _ width = " match _ parent "
Android:layout _ height = " match _ parent "
Android:layout _ margin left = " 1 10dp "
Android:layout _ margin right = " 1 10dp "
Android:clip children = " false " & gt;
& lt/Android . support . v4 . view . view pager & gt;
& lt/linear layout & gt;
Java code section:
// 1. Set the cache number of the project in the background.
mview pager . setoffscreenpagelimit(3);
// 2. Set the spacing between pages.
mview pager . setpagemargin( 10);
// 3. Assign the touch event of the parent class to viewPgaer, otherwise only one view object in the middle can be slid.
Container.setOnTouchListener (new view. OnTouchListener() {
@ Overlay
Public boolean onTouch (view v, sports event) {
Returns mViewPager.dispatchTouchEvent (event);
}
});