I'm building an app where I want to swipe images as though they were photos on a stack. In other words, if I swipe the top image I want it to animate moving in the direction of the swipe and have the next image underneath it visible the whole time. To accomplish this, I'm using a FrameLayout and two ImageView containers. I'm just alternating which one is on top. Meanwhile, as soon as a swipe occurs, the next image is loaded into the ImageView at the back using setBackground(drawable). My problem is that the ImageView at the back doesn't update it's image until I call bringToFront() on it, which means that as the top ImageView is animating, the image underneath is incorrect until the animation completes, at which point it abruptly changes to the correct image. I've tried calling invalidate() on the rear ImageView after setBackground(drawable) but this doesn't work. Anyone have any ideas on how I can get the image to update while it's behind?
UPDATE: Turns out I'm just not very on it today. I was updating the wrong ImageView and because the image loading was being done off the network, there was just enough lag to make me think it was happening after the animation completed.
Sounds to me like you wanna do something like an Image Slider.
There are great libraries existing for this purpose, this one for example:
https://github.com/daimajia/AndroidImageSlider
If you don't wanna use this, here are some tips:
Images on ImageViews are set with setImageDrawable(Drawable)
When your animation starts, set the new Image to your ImageView behind and slide the visible one away.
When the visible ImageViewhas slided away, set it's visibility to GONEand move it behind the second ImageView
Do this for every time a new image is loaded.
This should actually work.
You need a "ViewPager"
https://developer.android.com/training/animation/screen-slide.html
It has all the necessary handles to accommodate "N" number of images - also supports multiple swipe animations - default handlers - efficient memory management - prefetching - you are all in for a feast with this !!
Just make sure you get the "ImageView" in the layout of the "pages" you wish to develop on the "ViewPager".
Related
I need to have a set of Image views on a Linear Layout. &
==> onClick of an ImageView, I want to turn the Image to the back(Like Flipping Effect) & show another Image.
==> Again on click of that Image or another Image, I want to apply the same effect for that Image View & the Previous Imageview must come to the default position.
---> I just checked the FLIP ANIMATION in Android. But it is flipping the total view.
So I Just need How to flip an Image view in the same manner, with support from Android v2.2 & up
I think it is quite complicated but it is interesting & need some help how to achieve this as I am just learning the Android(& Coding).
Thanks.!!!
You can use this small library to do that :
https://github.com/castorflex/FlipImageView
I want to create an image auto scrolling for an outer-space type of game. To make it more exact, I want to load 2 background image that uses a single image occupying the whole screen and auto-scroll it alternatively to create an animation that the background image is moving. Don't get confused with auto scrolling and and shifting to another image automatically. I really meant auto scrolling like moving background using 1 image.
I did some research but what I saw are segments of java codes that made me confused. If possible can anyone provide me an example? From loading the image from xml (should I use an imageview with this? or just set the background image of the layout?) and how I should process it in java code to make an image autoscrolling.
Any ideas guys? Thanks! Sorry for asking too much.
I'm trying to create a stacked image gallery, this is a gallery on which all the pictures are overlaying each other in a stack(or pile), for example: a card pile, and the user would be able to see and touch just the upper image and to flip/throw it out of the screen(with translate animation). After throwing the first picture the user will see the second picture that was hidden underneath the first one and so on.
I didn't find a similar gallery in other apps except to "weheartpics" (for Iphone off course)
The line of solution that I'm following now is to create a FrameLayout, adding some overlaying pictures on it, to delete the upper picture when the user touch it(instead of throw it out of screen).
Use StackView, available on API Level 11 and higher.
Why not use a ViewPager and flip through your images from left to right? You can then utilize FragmentStatePagerAdapter to prefetch and cache your images as use flips through these
All right - here's another way:
Add ViewSwitcher with 2 ImageViews
Since you can't use drag and drop library look for some alternatives but generally you want implement dragging the top image. Hopefully that will expose the hidden image but if not you will have to swap images when the drag starts
Implement gesture performed listener to listen for the flick events on the top image
When image is flicked away:
a. Swap image views in ViewSwitcher (if not swapped already for the drag-n-drop)
b. Pre-load next image into hidden ImageView
Otherwise return top image into original location (don't load anything into hidden ImageView)
Ok, the solution for that problem was to use frameLayout and to add to it imageView from the code. It's easy to apply animations on the images and to remove/add them after the animation begins.
Is it possible to draw an image over another view (like a button) and still have the view work normally? The user would still be able to click on the button even though there is another image on top of it. I want to draw some mostly transparent pngs over my layout for lighting effects, but I want to make sure everything will still work correctly.
Try using a RelativeLayout with an ImageView on top of the widget(s) in your app. See this question for a quick example.
I've been doing the following for the last three days without any success.
Suppose I have one image. I have set that image invisible in my XML layout. Now I want to make it visible through animation. Suppose translate animation.
Suppose there is point A and point B. On point B I have already set the image invisible. From point A I want a translate animation effect. And when it completes, the image B becomes visible.
Please help me.
try using ViewFlipper (or ViewAnimator) setting your ImageView as children and defining animation effect for transition