what does ImageSwitcher actually DO? - android

I'm trying to snaz up my android apps and I see that ImageSwitcher is being referenced a lot for all sorts of animation tasks, but the google docs are totally spartan and don't describe anything other than the methods that are in the class. Meanwhile the examples all make use of gallery, and don't explain why.
Does anyone have a link to (or care to explain) any info on what the class actually does and how it's meant to be used?

I can't give a definitive answer as I've never used it. My best guess comes from working down the inheritance chain...
ViewAnimator...
Base class for a FrameLayout container that will perform animations when switching between its views.
ViewSwitcher
ViewAnimator that switches between two views, and has a factory from which these views are created. You can either use the factory to create the views, or add them yourself. A ViewSwitcher can only have two child views, of which only one is shown at a time.
Then looking at another direct subclass of ViewSwitcher...
TextSwitcher
Specialized ViewSwitcher that contains only children of type TextView. A TextSwitcher is useful to animate a label on screen. Whenever setText(CharSequence) is called, TextSwitcher animates the current text out and animates the new text in.
So reading between the lines, an ImageSwitcher is a ViewAnimator which is optimised for images (i.e., drawables) and as it inherits directly from ViewSwitcher it can only have two images.
So, paraphrasing the TextSwitcher overview, I would say that...
Whenever <insert setImageXXX method here> is called, ImageSwitcher animates the current image out and animates the new image in.
As I said, it's just a 'best guess'.

Related

Transform/Animate View in Activity1 to View in Activity2

I have two ImageViews which contain the same image. The Views are located in two different Activities. I want an Animation which - for the user - transforms the Image1 to Image2.
Is it possible to create a Transformation or Animation which resizes and repositions the ImageView from Activity1 to the location and size of the ImageView of Acitivity2?
Hope I made my point somewhat clear...
Thanks!
Ron
No (if I understand your question correctly). Activities are independent. All you can do is pass the attributes (like size, bitmap etc) from first ImageView and apply to second one. Or merge these two activities in one.
You could only achieve what you describe with very carefully timed custom activity transitions combined with animations for the ImageViews. If is possible to create your own Activity transitions, see Activity.overridePendingTransition(). See also this official guide for general info on creating Animations.
If possible, consider re-designing so you can transition between Fragments within the same activity, or with a ViewSwitcher e.g.:
viewSwitcher.setInAnimation(this, R.anim.in_animation);
viewSwitcher.setOutAnimation(this, R.anim.out_animation);
viewSwitcher.showNext();

View Flipping in Android using same activity

I am new to android therefore I got a little bit lost with all those ViewFlipper, ViewSwitcher, ViewAnimator and ViewPager. Moreover, I am not sure what's happening under the hood.
Basically I have an activity which shows some data. With swipe (or button, doesnt matter) I would like to scroll the view and get to another page (as seen in the picture below).
Is it possible to implement something like that without changing to another activity?
I am a little bit confused regarding views and access to the design elements. How those pages are located each to another? e.g. If I am currently seeing Page1, can I modify content of Page3? Or plainly saying, are all page views loaded all together? As if I set setContentView(R.layout.xlayout); then I can access only xlayout elements.
But if I use same activity, then I have a thread there which updates a counter on Page1, if I change view to Page 2, the counter will not find Page1 Counter TextView and will complain.
As I Understand Android 4.0 has ViewPager which is similar to the seen in the picture. I am using GB. Should I use support library or can I just go around and implement something similar without importing any libraries?
(Sorry, my description is a little bit messy)
Yes, you can use ViewSwitcher, ViewFlipper and ImageSwitcher depending on your requirements.
ViewSwitcher may have two childs at max. And these child might be a View or an object of subclass of view.
ViewFlipper: May have as many childs you want. and these child might be a View or an object of subclass of view.
ImageSwitcher might be used to switch images over.
By using view flipper you can display one item at a time, and adding a gesture overlay, you can apply sliding effect. To apply View Flipper, you need to add all the views to ViewFlipper, and showNext and showPrevious methods are used to show next and previous child.
You need to use a ViewPager to have the same behaviour as in Google Play.
it only available on recent version of Android, but you can use the Compatibility Package to make it available for older version.
With a ViewFlipper you can't "scroll" between two pages.

Is it possible to reuse the views in ViewFlipper?

May be a dumb Question.But still, is it possible to reuse the views in viewflipper?
Now,i have three imageviews in a viewflipper.is it possible to have a single imageview and change the source to it?
You can probably reuse view if you want to take care of the bookkeeping your self. However the viewflipper requires at least 2 views. From the Android ViewFlipper Docs:
Simple ViewAnimator that will animate between two or more views
that have been added to it. Only one child is shown at a time. If
requested, can automatically flip between each child at a regular
interval.
You would have to remove the ImageView from the ViewFlipper and then put it somewhere else. You can't put it into two ViewGroups at the same time (you'll get an exception that the view has already a parent).
But this is an overhead which you simply don't need to do. Simply create new ImageViews and use them. The memory consuming part of an ImageView is not the object itself but the bitmap it draws so I really recommend to read this article.

Animate layout background image changes

Is it possible to animate the background image of a layout (RelativeLayout, LinearLayout, etc.) in Android? In one of my applications I am fetching an image from the internet and displaying it as the background image once it's loaded. It would be really cool if the background image was swapped out using a fade effect or something like that.
I've tried quite a bit, but couldn't seem to find a solution. It's always the layout that's animating and not the image itself.
Might be your best bet to just layer your layout in a FrameLayout or RelativeLayout with a ViewSwitcher behind it. See the demo (and related layouts) in the Android API Demos app (that uses an ImageSwitcher, which is a special-case adapter-based subclass of ViewSwitcher). It does mean an extra ViewGroup level in your app, but unless you're doing something especially complicated (nesting these in ListView rows or something) it should perform just fine, and handles the transition animations for you.
You could also just use WebImageView from DroidFu, which does most of the annoying legwork for you.

What's the difference between ViewFlipper and ViewSwitcher

They both inherit ViewAnimator. I know that ViewSwitcher allows only two views, while ViewFlipper allows more. But why did Android create ViewSwitcher, if it is just a ViewFlipper with 2 views? Are there any other differences? On what condition will be using the one superior than the other?
From what I can tell, ViewSwitcher is used if you want to switch between two views like you said. Useful if you have 2 views that you have to go back and forth fairly regularly. And the class implements a ViewFactory if you wish to use it.
However, ViewFlipper can be used if you want to periodically change the views. Say like an automated flipping book of some sort. Though a custom-adapter gallery is much better at this.
And yep, that's all. They really aren't that much more useful than the ViewAnimator. Why Android development makes anything is really a mystery to me.
I would normally just prefer using a ViewAnimator because it gives you more freedom and thus flexibility in how you design. But if you want features like the ViewFactory and you only got 2 views use the ViewSwitcher. If you want to be able to periodically change views use ViewFlipper. If you don't need either use a ViewAnimator.
ViewFlipper supports more than two views, ViewSwitcher only supports 2.
I'm not sure if there's any big differences between them but from what I've gathered the difference is that ViewSwitcher is used in circumstances where the view is the same but the data is different - like on a calendar app - we're just changing the data in the view.
ViewFlipper is allowed in app widgets, while ViewSwitcher is not.
https://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

Categories

Resources