Imageswitcher Implementing the Guide page effect

Source: Internet
Author: User

:

Layout Code:
<?xml version= "1.0" encoding= "UTF-8"?><framelayout xmlns:android="Http://schemas.android.com/apk/res/android"  Android:layout_width="Fill_parent"android:layout_height="Fill_parent">                               <imageswitcherandroid:id="@+id/imageswitcher"android:layout_width= "Fill_parent" android:layout_height="Fill_parent">                            </imageswitcher>    <relativelayoutandroid:layout_width="Fill_parent"android:layout_ Height="Wrap_content"android:orientation="vertical">                                <linearlayoutandroid:id= "@+id/ll_view"android:layout_width=" Fill_parent "android:layout_height=" Wrap_content "android:layout_alignparentbottom ="true"android:layout_marginbottom="30DP"android:gravity=" Center_horizontal "android:orientation=" Horizontal ">                                                                                            </linearlayout>    </relativelayout></framelayout>
page code:
 Public  class imageswitcheractivity extends Activity  implements  Viewswitcher. viewfactory, View. Ontouchlistener {    Private int[] imgids;//Image ID array    Private intcurrentposition;//The currently selected picture ID number    PrivateImageswitcher Mimageswitcher;references to//imagaswitcher    Private floatDownx;//press the x-coordinate of the point    PrivateImageview[] tips;//Point points Group    PrivateLinearLayout LinearLayout;//container for loading point    @Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_switcher); Imgids =New int[]{r.drawable.bg, R.drawable.c2, r.drawable.c3, r.drawable.c4, R.drawable.c5, R.drawable.c6, R.drawable.c7,        R.drawable.c8, R.DRAWABLE.C9}; Mimageswitcher = (imageswitcher) Findviewbyid (R.id.imageswitcher);//instantiation of ImageswitcherMimageswitcher.setfactory ( This);//Set factoryMimageswitcher.setontouchlistener ( This);//Set Ontouchlistener, we switch pictures with touch eventsLinearLayout = (linearlayout) Findviewbyid (R.id.ll_view);//Indicator layoutTips =NewImageview[imgids.length]; for(inti =0; i < imgids.length; i++) {ImageView Mimageview =NewImageView ( This);            Tips[i] = Mimageview; Linearlayout.layoutparams Layoutparams =NewLinearlayout.layoutparams (NewViewgroup.layoutparams (Layoutparams.wrap_content, layoutparams.wrap_content)); Layoutparams.rightmargin =3; Layoutparams.leftmargin =3;            Mimageview.setbackgroundresource (r.drawable.page_indicator_unfocused);        Linearlayout.addview (Mimageview, layoutparams); }//Where the previous interface came fromCurrentPosition = Getintent (). Getintextra ("Position",0);        Mimageswitcher.setimageresource (Imgids[currentposition]);    Setimagebackground (currentposition); }//Set the background of the selected tip    Private void Setimagebackground(intSelectitems) { for(inti =0; i < tips.length; i++) {if(i = = Selectitems)            {Tips[i].setbackgroundresource (r.drawable.page_indicator_focused); }Else{Tips[i].setbackgroundresource (r.drawable.page_indicator_unfocused); }        }    }@Override     PublicViewMakeview() {FinalImageView i =NewImageView ( This); I.setbackgroundcolor (0xff000000);        I.setscaletype (ImageView.ScaleType.CENTER_CROP); I.setlayoutparams (NewImageswitcher.layoutparams (Layoutparams.match_parent, layoutparams.match_parent));returnI }@Override     Public Boolean OnTouch(View V, motionevent event) {Switch(Event.getaction ()) { CaseMotionevent.action_down: {downx = Event.getx ();//finger pressed x-coordinate                 Break; } CaseMOTIONEVENT.ACTION_UP: {floatLASTX = Event.getx ();//Lift up when the x-coordinate is greater than the time it is pressed to display the previous picture                if(Lastx > Downx) {if(CurrentPosition >0) {//Set animationMimageswitcher.setinanimation (Animationutils.loadanimation (Getapplication (), r.anim.left_in));                        Mimageswitcher.setoutanimation (Animationutils.loadanimation (Getapplication (), r.anim.right_out));                        currentposition--;                        Mimageswitcher.setimageresource (imgids[currentposition% imgids.length]);                    Setimagebackground (currentposition); }Else{Toast.maketext (Getapplication (),"It's already the first one.", Toast.length_short). Show (); }                }if(Lastx < DOWNX) {if(CurrentPosition < Imgids.length-1) {mimageswitcher.setinanimation (Animationutils.loadanimation (Getapplication (), r.anim.right_in));                        Mimageswitcher.setoutanimation (Animationutils.loadanimation (Getapplication (), r.anim.lift_out));                        currentposition++;                        Mimageswitcher.setimageresource (Imgids[currentposition]);                    Setimagebackground (currentposition); }Else{Toast.maketext (Getapplication (),"to the last one.", Toast.length_short). Show (); }                }            } Break; }return true; }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Imageswitcher Implementing the Guide page effect

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.