I have a rectangular Imageview that responds to touch (it rotates by a specific number of degrees, using animation). The imageview has an ontouchlistener attached to it.
However, once it has rotated, it still responds to touch only at its original (pre-rotation) location. Even though I have setfillafter to true.
My theory is that the rotation is for display purposes only... is there a way to detect a touch on a rectangular imageview rotated at an angle - e.g. 45 degrees?
When animation is applied to a view in android, only the pixels of the view are shifted while the hit area remains in the same position.
To actually move a view, you will need to add a animation listener to the view and manually change the view position on animation end.
Related
I will try to explain.
I have a ListView with its adapter which defines the method getView (as usual) for retrieving the appearance of the cells. The final appearance of the ListView is the one shown.
As you can see the first arrow is rotated of 180 degrees. It has been rotated with an animation once I clicked on it. If I'd click on it again it would be rotated to the original position again. The rotation of 180 degrees is maintained with the fillAfter parameter of the animation (then it is not fixed definitively once the animation completed).
The problem is the following: when list view is scrolled and the cell with the rotated arrow is brought out and in again the cell's view is loaded again. At this point I need to rotate the arrow again. I have two ways:
use arrow.setRotation(180f)
use the same animation used before with the duration set to 0
Both the ways have a problem:
The rotation is fixed, then when I call the method for rotating the arrow to its original position the arrow is ALREADY on its original position (because of setRotation)
The rotation is not immediate, then, when the cell is brought out and in again, for an instant it points right and after a moment left
How can I solve this problem?
I need to rotate the arrow before of bringing it in again but without fixing its state as rotated of 180 degrees.
I will suggest you if you have less posibilites of items to be placed in listview then use Dynamic Linearlayouts in ScrollView instead of ListView. As ListView generates many complexities in its own layout In making custom adapter like putting edittext in listview and do some action like delete/animation on UI component of yout listItem.
I have a panoramic background as a sky that i want to move from left to right and then from right to left to simulate a moving clouds animation as a screen background .
This should repeat indefinitely and after goin to the right most then return back to the left most..
I have tried the following:
Animation left = AnimationUtils.loadAnimation(MainActivity.this, com.icare.kids.R.anim.view_transition_out_right);
left.setRepeatCount(Animation.INFINITE);
left.setRepeatMode(Animation.REVERSE);
left.setDuration(3000);
findViewById(id.cloud).startAnimation(left);
But this does not seem to work... any solution for that ?
I am currently setting the image to an ImageView as follows:
<ImageView
android:id="#+id/cloud"
android:layout_width="3000dip"
android:layout_height="wrap_content"
android:layout_below="#id/topbar"
android:scaleType="matrix"
android:src="#drawable/bgpan" />
how can i set the image to the screen to start from the left most like this below, so to help in the panoramic animation effect:
The best solution that is efficient and fast on all phone ranges was to actually only animate the clouds while keeping the background static.
you can also add some variable to the speed that would add some randomization to the speed of the clouds so you don't get a monotonic looping.
Implementation details and solution was taken from this answer
One thing you might be able to try is using a Viewpager object with fake drag, where you continually re-add the background to new views that get generated, while disabling user input.
This will give the illusion of what you are trying to do.
So lets say you have 4 views in your adapter, each view contains just one of the image assets that fills the whole screen, and Viewpager's fake drag pans from View A to View B, draws View C and draws View D, then it fake drags from View B to View C and draws View A again
I'm curious if that would work for you
In my android application I am stuck in a problem and nothing seems to work for me.
I have an ImageView on the top of another ImageView inside a relative layout.
Now I need to resize the imageview on top when user touches one of its corners and drags.
Just like a cropping frame we generally see. When we drag any one corner, then the diagonally opposite corner must remain fixed and the resizing must be done across the corner which is being dragged.
What I am doing is setting OnTouchListener and getting new/dragged coordinates on Action.MOVE then I tried to resize using Bitmap's createScaledBitmap. This does resize the image view but not across the corner which is being dragged. I am totally confused .
How I can use the coordinates to draw an Image View just like we do it while drawing a rectangle using Canvas.
Please help.
I wouldn't do this in an ImageView. I would subclass View and override onTouchEvent and onDraw to handle the input and draw all the various components. You have to break this down into it's components and manage a number of objects in this view.
You have a Rect that represents the size of the crop area. This probably defaults to the size of the control. In onTouchEvent, you need to test for an area around each corner and then keep track of which corner is being dragged to resize your Rect appropriately.
You don't have to call createScaledBitmap each time you draw it, and you probably shouldn't because you are flirting with an OutOfMemoryException at that point (clean up your Bitmaps too slowly and you'll find out the hard way what this is). Just decode the Bitmap when the control gets created and draw it to the canvas using a destination Rect.
Lots of code to write, but it sounds like a fun project. There's no easy way to drop in a control like this (if I'm understanding you correctly). You have to manage the touches, drags, and the destination rectangle inside the custom View.
I have an image I can drag on the screen thanks to an OnTouchListener.
While moving this image I draw a thin line that "binds" it to its original position.
Now when I release/drop the image, I have a TranslateAnimation which makes the image go back to its position or out of the screen, depending on the dropping area.
How could I redraw the line during the TranslateAnimation so that the image is still bound to its original position while moving?
In AnimationListener there's onAnimationStart, onAnimationRepeat and onAnimationStop, but I see no trace of a onAnimationProgress or so.
Is there a way to get the changing position of a view while animating? Other than an infinite loop on the view position and an if to check if its position changed...
I think you can achieve what you want by creating your own Interpolator for the animation and then whatever you want when getInterpolation() is called.
Is it possible to use ImageView to draw a panoramic picture? I.E. When you scroll to the end of the right edge of a panoramic picture, it should start showing the left edge of the picture. I know there is a panoramicgl project for android, but I was thinking of doing this manually. Right now, I have scrolling and zooming using Android's matrix.
Yes that is possible, but you need to have a scrollview too.
You could try to subclass ImageView and implement onTouchEvent() to listen to userinput that will modify the current focal point. If the focal point is moved, redraw the picture to an offscreenbitmap, e.g. with matrix.postTranslate(deltaX,deltaY), and redraw the portion of the image that has been shifted out of bounds on the opposite side.