(Android Control) ImageSwitcher introduction and instructions for use

Source: Internet
Author: User

1 ImageSwitcherImplemented FunctionsAnd actual running

The ImageSwitcher class provides the image switching function. through third-party operations, you can set the image displayed by the current ImageSwitcher and set the animation of the image conversion.

 

2How to Use ImageSwitcherWidget

 

2.1Configuration page file

<ImageSwitcher

Android: id = "@ + id/imageSwitcher1"

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

Android: layout_alignLeft = "@ + id/textView1"

Android: layout_above = "@ id/adLayout"

Android: layout_below = "@ id/topText"

Android: layout_centerVertical = "true">

</ImageSwitcher>

 

3Initialize ImageSwitcherWidget

Initialize the adapter of the ViewPager Control

 

ImageSwitcher1 = (ImageSwitcher) findViewById (R. id. imageSwitcher1 );

ImageSwitcher1.setFactory (This);

ImageSwitcher1.setInAnimation (AnimationUtils. loadAnimation (This,

Android. R. anim. fade_in ));

ImageSwitcher1.setOutAnimation (AnimationUtils. loadAnimation (This,

Android. R. anim. fade_out ));

ImageSwitcher1.setImageResource (R. drawable. girl2 );

 

4Switch the image direction based on the Interface sliding

OnTouchListener touchlistener =NewOnTouchListener (){

@ Override

Public BooleanOnTouch (View v, MotionEvent event ){

If(Event. getAction () = MotionEvent. ACTION_DOWN ){

DownX = (Int) Event. getX ();

Return True;

}Else If(Event. getAction () = MotionEvent. ACTION_UP ){

UpX = (Int) Event. getX ();

If(UpX-downX & gt; 100 ){

ImageSwitcher1.setInAnimation (AnimationUtils. loadAnimation (ShowPhotoActivity.This,

Android. R. anim. slide_in_left ));

ImageSwitcher1.setOutAnimation (AnimationUtils. loadAnimation (ShowPhotoActivity.This,

Android. R. anim. slide_out_right ));

ImageSwitcher1.setImageResource (R. drawable. girl1 );

}Else If(DownX-upX & gt; 100 )//{

ImageSwitcher1.setInAnimation (AnimationUtils. loadAnimation (ShowPhotoActivity.This,

Android. R. anim. slide_in_left ));

ImageSwitcher1.setOutAnimation (AnimationUtils. loadAnimation (ShowPhotoActivity.This,

Android. R. anim. slide_out_right ));

ImageSwitcher1.setImageResource (R. drawable. girl2 );

}

Return True;

}

Return False;

}

};

 

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.