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;
}
};