This article will talk about the use of Imageswitcher controls in Androidui development. Imageswitcher controls are similar to ImageView and can be used to display pictures, but Imageswitcher can be seen by name, mainly for the toggle display of multiple pictures. In this article, you will describe the settings for the basic properties of the Imageswitcher control and the invocation of common methods. At the end of the article, we'll show you some of the things that are covered in this blog with an example demo.
Imageswitcher is a picture switcher, which indirectly inherits from the Framelayout class, and ImageView compared to one more function, that is it said that the display of the picture switch, you can set the animation effect, similar to the light fade effect, and Zoojin right out of the sliding effect.
Since Imageswitcher is a control used to display pictures, ANDROIDAPI provides us with three different ways to set different image sources:
Setimagedrawable (drawable): Specifies a Drawable object to display for Imageswitcher.
Setimageresource (int): Specifies the ID of a resource to display for Imageswitcher.
Setimageurl (URL): Specifies a URL address that is used to show imageswitcher the image resource that the URL points to.
Animation effect setting
As described above, Imageswitcher can set the animation effect when the picture is switched. Support for animation effects is because it inherits the Viewanimator class, which defines two properties that determine the animation effect of a cut into a picture and the animation effect of cutting out a picture:
Android:inanimation: Effect when you cut into a picture.
Android:outanimation: The effect of cutting out a picture.
The above two attributes can, of course, be customized with XML resource files if you set them in XML, but if you just want to use some simple effects of Android, you need to set the parameters to "@android: Anim/animname" To set the effect, Where Animname is the specified animation effect. If you set it in code, you can use the Setinanimation () and Setoutanimation () methods directly. They all pass a animation abstract object, animation is used to describe an animation effect, generally using a Animationutils tool class to obtain. For the animation effect, not the focus of the blog, about the animation effect of Android, and then explain in detail.
For animation effects, the general definition is in Android. In the R.anim class, it is a final class, defined in the form of some int constants, where only two sets of styles are introduced, the fade effect, and the Zoojin right slip effect, and the official documentation is available if additional effects are required.
Fede_in: Light in.
Fade_out: Fade Out
Slide_in_left: Slide in from left.
Slide_out_right: Slide out from right.
The general use of words, through these constant names can be seen is what effect, here is not mandatory xxx_in_xxx must correspond to the Setinanimation () method, but generally if not set, the effect will be very ugly, suggest or group corresponding in and out set effect.
When using Imageswitcher, there is a special need to pay attention to the need to pass setfactory () method to set a viewswitcher.viewfactory interface for it, the Viewfactory interface is set to implement the Makeview () method, which usually returns a ImageView, and Imageswitcher is responsible for showing the ImageView. If Viewfactory is not set, Imageswitcher will not be available. The official documentation learned that the Setfactory () method is declared in the Viewswitcher class, and Imageswitcher directly inherits from the Viewswitcher class. The Viewswitcher function is similar to Imageswitcher, but Imageswitcher is used to show pictures, and Viewswitcher is used to show some view views.
As you can understand, the Makeview () method in Viewfactory returns a new view, which is used to display in Viewswitcher, and for imageswitcher, this usually returns a ImageView.