I use the code below to display an image in the screen.
ImageView img = (ImageView) findViewById(R.id.imageView1);
img.setImageResource(R.drawable.car);
I want to let the user, to reposition it by finger to any place.
which one I can use?
setOnTouchListener
onDrag
This is when I have two cars. and the background is another bitmap image.
You can do so.
But its a bit complicated.
Have a look at this great tutorial:
http://blahti.wordpress.com/2011/01/17/moving-views-part-2/
You can use both but it depend upon your requisite like what you what ie you just want to re position your image where ever user touches on screen or else you want to longpress it and then drop where user the touch movement end ............. for Ist case go these Move ImageView around inside RelativeLayout and for second case use these Drag and drop images in android
To change the image position by finger in java android you will need to work with
Surface View and onTouchListener both of them have described precisely in Android Developer Site.
You also can check this question from which you will get help
Touch and drag image in android
Happy Coding.
Related
I am developing Android application for book. I create total images for book is one hundred. In the app two buttons present one is previous button and second is next button. The previous button and next move images forward and back correctly. But now I want to implement zooming effect for image. But the text are some smalls not seen correctly. Please help. Thank you
Below are the options available for implementing zoom in-out effect in android Imageview.
How to implement zoom effect for image view in android?
Android imageView Zoom-in and Zoom-Out
https://github.com/chrisbanes/PhotoView
https://github.com/jsibbold/zoomage
Much better than the offered alternatives here IMHO
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".
I'm working on image multi touch events, that have an image with touchEvents like googleMaps's touchEvents( pinchZoom and move togather with 2 fingers ), I tried GestureImageView and cusomized it and could implement that. but I'm not sure it is correct way or there is another method for it.Is there any way to do that ?
also I want to show different parts of the large image by clicking on each part and show theme so that it seams that camera moves view on the image.
Is there any library or any tools for this purpose in android?
I will be appreciate if help me.
Thank you.
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'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.