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();
Related
What purpose does FrameLayout serve in Android? Is there any specific scenario for which it is designed for?
In my Android application, I have a scenario where I have to show two ImageViews, one over the other. This is a .png image file with a 9-patch drawable over this image.
Which ViewGroup should I use for this purpose: RelativeLayout or FrameLayout?
I also want to know the different scenarios that each of the ViewGroups should be used for.
I don't recall how i got to this question but here is my answer that could help anyone:
As you can see here
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.
In general is not useful to have 2 views one over the other because you're going to have overdraw effect (an area of the screen that is getting drawn by the gpu more than once which is really useless).
If you really have to, then you need to use the onDraw method (you can see an example here) and Canvas API (have a look here) and the clipRect method (you can see an example here)
Regarding FrameLayout or RelativeLayout, if you want to keep things simple or your activity has already enough nested layouts, better use FrameLayout. In 2017, there is the constraint layout which could be of some help as well.
Yes, you can use a FrameLayout in your scenario.
What is the best way to create a slideshow in Android?
Basically, what I need is to slide through a collection of LinearLayout or RelativeLayout objects, that contains inside them different views, ex: an ImageView and a TextView overlayed on that image.
On the bottom of the screen, should be some bulled points that will keep track of the currently element in the gallery.
To give an idea take a look at this jQuery implementation: http://slidesjs.com/
(I don't need the "left"/"right" controls, and the bulled points also dont need to be clickable, as in example)
Also, the slideshow should be in a cycle.
Maybe not the best, but I used a Gallery.
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.
I basically have 5 text views that fill in one on top of the other. Rather then just all showing up like they do now, I want them to all come in with some animation, one after the other. Anyone have a link to a tutorial on how to animate TextView objects? only one I saw in the android docs involved using images as well as needing an image in the background.
Animating a TextView is basically like animating any other view. If you want it to show up one after one, you can implement an AnimationListener and start the corresponding TextView when the previous has finished.
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'.