I want to zoom in to a specific point on screen. I have a layout containing child image views. Scaling layout is working great but the problem is in content images; when I click one of them, after scale layout, it triggers click of another image. The positions of the images are still the same so the onclick trigger is not scaled. How can I scale layout with its image children simultaneously?
This is my scale code:
ScaleAnimation zoomInAnimation = new ScaleAnimation(1, 2f, 1, 2f, zoomX, zoomY);
subcategoryLayout.startAnimation(zoomInAnimation);
I'm not sure I properly understand your question, but it sounds as if you are not filling the elements after the animation ends. You might try using setFillAfter
Related
I am creating layout for finger selection. In this I am trying to achieve click events for each individual finger. This layout should be uniform on any type of screen resolution.
My approach:
Inside relative layout, I am assigning radio buttons (not radio group but individual) to each finger inside hand image using margins and padding but it is not resting properly over finger image. They are slightly moving left or right.
Problem in this - radio button positions is changing if screen resolution changes.
I failed to find library for such click events. Also in SO I didn't find any related questions. Can someone guide me in this to library or example or better approach than this?
A several years ago I worked on the similar task. Unfortunately, I don't remember the whole solution, but idea was pretty simple. In my case it was an image of the map where a user could select a district by tapping the map. I knew the resolution of the original image that I used to display in UI. I encoded each district against its boundaries so it gave me a list of pair's number. I had a touch listener attached to ImageView that was used to display the map. So every time a user clicked on the map I got a position of his click, multiply this value by a scale factor(this one was calculated based on the size of original image and the one that was scaled by Android). Then I checked if that value laid in any polygons.
So to make it more clear:
Let width, height = size of original image
x, y = user touch
scaleWidth, scaleHeight = size of the image displayed by Android on the user device
scaleX = scaleWidth / width, scaleY = scaleHeight / height
originalX = scaleX * x, originalY = scaleY * y
Then check if originalX and originalY fits in polygons. In your case those polygons could be just squares around every finger.
For a pure design stuff I need to perform some animation on a RecyclerView Parent. These animations include a scale and a rotation on Y axis. When recyclerview is not populated everything is okay, but if I add some elements (not so much) animation become very laggy. I suppose because on each frame the recyclerview tries to refresh all its view even if nothing in the adapter has changed.
This is the code I use to animate the parent:
final float scale = 1 - 0.3f * slideOffset;
panel.setPivotX(0);
panel.setPivotY(panel.getHeight() / 2.0f);
panel.setScaleX(scale);
panel.setScaleY(scale);
float angle = -slideOffset * MAX_ROTATION_ANGLE;
panel.setRotationY(angle);
'panel' is my custom layout view where is located the recyclerview plus other views, 'slideOffset' is a float between 0-1 defined by user's finger on the screen.
I've tried also:setHasStableIds(true);to the adapter but nothing changed, and even setLayerType(View.LAYER_TYPE_HARDWARE, null);doesn't help.
I have a linear layout with three images in it. On the click of any ImageView I want to animate the whole linear layout. The animation consists of two animations - scale and transform. I don't know how to perform this animation.
This is what I want -
Image 1 - Before Animation
Image 2 - After Animation
I want to not only animate the View but actually shift the view to its new location with animation. After animation I should be able to click the Images at their new locatoin not the old location.
How can I perform this? Please help me out.
I used nineoldandroids library to achieve this animation. I used two animation: translation and scaling.
Translation:
ObjectAnimator.ofFloat(frameCategoryScroll, "translationY", 0, -yValue).setDuration(600).start();
yValue is the the value in y axis upto which I want to translate.
Scaling:
ObjectAnimator.ofFloat(frameCategoryScroll, "scaleX", 1.0f, 0.6f).setDuration(600).start();
ObjectAnimator.ofFloat(frameCategoryScroll, "scaleY", 1.0f, 0.6f).setDuration(600).start();
I have a listview that I am implementing pinch zooming on. I resize each child view of the listview which changes the row height. When these rows are resized, the top item of the list view remains stationary and the items below it move up to recover the slack space.
I'm trying to implement the pinch zoom in 2 parts. First, make the zoom origin the center of the visible list (right now it's the top, like I said). Second, adjust the origin based on the focal point of the zoom gesture.
My problem is that I can't smoothly adjust the origin of the zoom. The method I have right now does scroll the list, but it does it a few milliseconds after the view is updated (it actually looks pretty bad... It's really choppy).
Is there a better way to do what I'm doing in the code below?
mMsgs is a listview.
// Center align the scroll
int yviewspace = mMsgs.getHeight();
int newyviewspace = (int) (yviewspace * zoomratio);
//mMsgs.scrollBy(0, -(yviewspace - newyviewspace) / 2); //This is smooth, but, sadly, it doesn't work on listviews.
mMsgs.smoothScrollBy(-(yviewspace - newyviewspace) / 2, 0);
I am trying to create a mini progress bar that will indicate how much data a user has used. It doesn't even need to animate, I just need it to change in size based on a variable I have set up. So when I load up the screen, how much of the progress bar is filled up will depend on a variable I have set up in Java.
I have managed to get this working horizontally by using
scale = new ScaleAnimation(0.0f, 1.5f, 1.0f, 1.0f,1.0f, 1.0f);
This will start the image from nothing and stretching out to its full size, so I can use it as a horizontal progress bar which is great.
Now I woulda thought doing this vertically instead would be a simple matter of just changing the fromY to 0 and the toY to the new size I want. However when I do this, by changing the fromY to 0.0f and the toY to 2.0f, the image actually moves and stretches at the same time rather than stretching. Also the image moves position for some reason. It starts off higher up than where I positioned in using XML, and moves down to the original position and stretches out to the new scale I set up.
The code I use to try and stretch it vertically is
scale = new ScaleAnimation(1.0f, 1.0f, 0.0f, 2.0f, 1.0f, 1.0f);
So can someone please explain why it stretches horizontally fine, but when I try to stretch it vertically, it suddenly moves and stretchs at the same time.
Would be very grateful for any help.
I appreciate you have solved the animation issue you mentioned, but based on you saying you don't even need the bar to animate, the ClipDrawable class may make your life simpler. You can define one in an xml layout and then set the clip level from your code, which will clip the given drawable by the given amount.
Check this out for more details on how to use it:
http://developer.android.com/guide/topics/resources/drawable-resource.html#Clip
Hope that's of some help.