Android ApiDemos example resolution (124): Views-& gt; ImageSwitcher

Source: Internet
Author: User

The following is an example of Android ApiDemos (97): Views-> Animation-> Push. ViewFlipper, ViewFlipper, and ViewSwitcher are both subclass of ViewAnimator and ViewAnimator (subclass of FrameLayout) supports the animation effects during switching between different views. ViewAnimator should be a subclass of FrameLayout. Therefore, the child views contained in ViewAnimator are stacked together, generally, you can View the top View.

ViewFlipper can contain more than two sub-views. Each sub-View is automatically displayed during regular switching. ViewSwitcher can only contain up to two subviews. Only one View is displayed at a time. It has two subclasses: TextSwitcher and ImageSwitcher. In this example, ImageSwitcher is used to switch between two contained images.

ImageSwitcher defines setImageDrawable, setImageResource, and setImageURI. You can specify an image for ImageSwitcher in different ways. Each time you call these methods, when switching between the newly added image and the previously displayed image, the animation effect specified by setInAnimation and setOutAnimation is used:

[Java]
MSwitcher = (ImageSwitcher) findViewById (R. id. switcher );
MSwitcher. setFactory (this );
MSwitcher. setInAnimation (AnimationUtils. loadAnimation (this,
Android. R. anim. fade_in ));
MSwitcher. setOutAnimation (AnimationUtils. loadAnimation (this,
Android. R. anim. fade_out ));

MSwitcher = (ImageSwitcher) findViewById (R. id. switcher );
MSwitcher. setFactory (this );
MSwitcher. setInAnimation (AnimationUtils. loadAnimation (this,
Android. R. anim. fade_in ));
MSwitcher. setOutAnimation (AnimationUtils. loadAnimation (this,
Android. R. anim. fade_out ));

 

In this example, ImageSwitcher is displayed on the top of Layout, and the thumbnail of the image is displayed using Gallery. For details about Gallery usage, see Android ApiDemos example resolution (119): Views-> Gallery-> 1. Photos

When you select a thumbnail in the Gallery, ImageSwitcher is used to display the corresponding large image:

[Java]
Public void onItemSelected (AdapterView parent,
View v, int position, long id ){
MSwitcher. setImageResource (mImageIds [position]);
}

Public void onItemSelected (AdapterView parent,
View v, int position, long id ){
MSwitcher. setImageResource (mImageIds [position]);
}

 
Author: mapdigit
 
 

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.