This question is about performance. My goal is to make an animation which flips view vertically. What is better, to flip the actual View inflated from XML, or make a snapshot of that view and flip bitmap image?
One of the ways to flip is described here:
http://2cupsoftech.wordpress.com/2012/09/18/3d-flip-between-two-view-or-viewgroup-on-android/
But how performant is it?? And isn't better to flip a bitmap?
I would suggest using card flip animation as described here. It works fine. (But it depends on your View as well)
Snapshots are heavy in memory. Besides, you have to create the second snapshot too, if the second Activity isn't loaded yet.
Related
background
I've made a simple app called "LWP+", which shows a cropped image . When the user chooses a photo, I save it into a file, and then do the cropping when needed. I do this by using 2 libraries. One for allowing the user to choose the cropping rectangle, and one for the actual cropping.
The problem
This is just for a normal cropping, but a nicer feature I'd like to add is a way to scroll through the content of the entire given image, at least horizontally.
On a normal Activity, I'd probably use a ViewPager that has an ImageView for each page.
But here a live wallpaper doesn't really have a layout.
What I've found
There isn't much of information about live wallpapers in general, but when I've searched for scrolling of an image in it, I've found just how to move the canvas.
This can actually be a good idea, of somehow having bitmaps (or partial decoding of the image) around the current position, and translating the canvas as needed. I could also use a GestureDetector class to identify flinging, but this is only a tiny fraction of what's needed to do a nice scrolling of a zoomed image.
It is also very complex, as it requires good memory considerations in mind.
If I could use a normal view, I could have used a ViewPager, or even a third library that shows an image and allows to scroll in it freely , like in the gallery app (such as this one).
The question
Given a View of any kind, such as ViewPager or another, is it possible to host it somehow inside the LiveWallpaper, to let it show content, and to handle touch events ?
Alternatively, is there an efficient way to view content as I've written, yet in a live wallpaper? Meaning viewing a portion of a large image, while allowing to scroll though it (like a ViewPager, but maybe even freely like on a photo viewer library, in all directions) ?
I would like to know what is the difference between SurfaceView and ImageView and their usage scenarios. Both seem to be the same. Kindly direct me if there are proper links which I had probably missed.
Some advantages and differences of a surface view:
Better rendering mechanism. threads can update the surface's content without using a handler. This helps for better performance in games and too much animation.
So if you need to update GUI rapidly or if the rendering takes too much time and affects user experience then Surfaceview is advisable instead of imageview.
Surfaceviews cannot be transparent, they can only appear behind other elements in the view hierarchy.
Surfaceview has dedicated buffer, too. So it costs more resources than imageview and other views.
Here is a reference links which you could refer to understand better.
Difference between SurfaceView and View?
Hope this clears some doubt.
Basically the difference lies on how both the views are being processed internally.
Surface View, has more rendering options. The view implicitly can render the images or animations using the graphics hardware. It doesn't need any third party support ( or makes less use of ) to make the animation work.
Preferably used when you want too many animations to be used. The View renders them automatically to the screen size. Ex: gaming applications.
Image View, is preferably when you want to display more of static images. The View render the images to any layout size. But when you have any animations on the page, the View takes support of GUI related conversions.
Basically, I have images that I'd like to to update them sequentially into the same view to create custom ProgressBar.
I found Tumblr to do just that with their ProgressBar(ImageView?).
Here I put the animation side-by-side to show how the image actually cross-fade from Aa into a camera.
Exactly what I wanted:
Cross-fading effect
Indeterminate
Use the same view (I dumped view hierarchy to check)
Animation during transition (The image actually pop a little when spinning and cross-fading into the next image)
So far I have tried:
1. Frame Animation,
this allows for unlimited item(s) with definable durtion. However, it
doesn't cross-fade the image and there's no way to listen to the
transition's event to apply other animation, etc.
2. Transition Drawable, this allows cross-fading between EXACTLY two drawables. So this doesn't allow for the number of items and interminate duration as well.
I also came across CrossFadeDrawable by Romain Guy just now but it looks like it's only coded to support only two Drawable.
Right now I am not very sure if I'm approaching in the right direction or is there something I need to learn in order to do this kid of effect?
I'm not sure if you are approaching this direction but isn't this what you are looking for:
http://www.youtube.com/watch?v=atH3o2uh_94
At the moment, I am using Euro 2012 app and it has some interesting layout parts. If you go to matches->knockout screen, you'll see 3 screens like this.
If you slide left or right, you move between them not like between one activity to another, but just like all these elements are laid on one big canvas and you slide each screen into focus. Even thou, if you slide left/right, the screen cannot be stopped in the way that half of each image is visible, so I guess it's not a big canvas. Somehow you can slide screen like one big image, and yet it always lock perfectly as if they used 3 activities for this.
How did the do this?
It's a ViewPager, available in Android support package and described in their blog.
The designing is not so much difficult, As i think to draw that boxes showing quarterfinals, semifinals.
They having layout( we can do by placing image in background also).
The major role played by FrameLayout which shows you that effect(emphasis), the flages are fetch from url as matches are decided(not essentially images only names are sufficient as flags came inside app and gets applied as updated).
After your click i think the start image gets change it's just replacing that image with new one.
As you said they are not on single canvas (but if they did customization of heir Viewpager that it's not stopping in between activities), but i think it's on single canvas.
If your taking about quickness of loading and all it's up to you as much code and processing you optimized it gives you smooth feel and fast processing.
We can appreciate the work but we can not say it's too much difficult as i think it's quit easy...
Hope this explanation helps you to understand ....
i have to take something like a screenshot in my android application. It is not a screenshot, it should be a "viewshot". It is about to render the complete content view on a bitmap.
I have found the solution to render the content view of the activity on a bitmap, but if the content view is bigger than the activity, it is only the visible part which gets drawn onto the bitmap.
Does anybody have a solution for this, or some ideas what to google?
Thanks
The content view is never "bigger than the activity", by definition.
The content view may be scrollable, but most scrollable things are either AdapterViews or use a tile mechanism (e.g., MapView), none of which are rendered until they are scrolled into a visible position. There is no stock way to make a "viewshot" of things that have not been rendered. You are welcome to create your own AdapterViewShotter that iterates over the items in the Adapter, captures each to a Canvas, and stitches the lot together into a huge image.