setRotation() on RecyclerView's parent causes lag - android

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.

Related

What's the difference about the result of a call to view's offsetTopAndBottom and setTranslateY?

Internally, both mTop and translateY determines the view's position along with the Y-axis, which one should be chosen when animating a view.

ObjectAnimator from left off screen clears image that will be covered up

The ObjectAnimator below works great.
screenWidth = 800;
ObjectAnimator moveOver =
ObjectAnimator.ofInt(localMovingView, "left", screenWidth, 0)
.setDuration(500);
moveOver.start();
But if I change screenWidth to move in from the left, it works badly. When the animation starts, the View that was there before the animation started instantly disappears. The new view covers up the empty space by the end of the animation. Both the new and old views are ViewGroups that have been added to a different ViewGroup
screenWidth = -800;
ObjectAnimator moveOver =
ObjectAnimator.ofInt(localMovingView, "left", screenWidth, 0)
.setDuration(500);
moveOver.start();
I can't find anything on SO that addresses this, so help would sure be appreciated. I have checked the disappearing view. It has mLeft = 0;
When animating the position of Views, it is best to adjust the properties translationX and translationY. These properties are not absolute, they are relative to the current X and Y positions of the view.
EDIT: Also, if the view appears at it's destination for a moment before proceeding with the animation, the answer to one of my previous questions may be useful. FragmentTransaction animation is working but appears glitchy

View coordinate in Screen

I have the next question:
Im developing an app that when i move a imageView and drop it, if the view drops under the half height of the screen goes to a (X,Y) position and if is over the half height screen, goes to another position.
I need to calculate the half of the screen generic, so i use the next code:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
halfHeight = displaymetrics.heightPixels / 2;
This works great, im trying in a screen 1920x1080, the code returns 540.
But when im going to see if when i drop the view is under or over the half, here is what i dont understand. i get the Y position of the view and is ok, what i dont understand is why the Y = 0 is not on the TOP of the screen, if i move the view to the top, i get a negative Y position like -260.
Someone can explain me why this happen?
Is there i way that the (0,0) position starts in the top left of the screen?
Greets, hope you understand
If you call getX() or getY() then you are getting relative values for x and y (relative to the view that the call was dispatched from). If you call getRawX() or getRawY() it will give you the absolute position of the view relative to the device's screen.
Most likely you are getting negative values of -260 because you are dragging the ImageView 260 away from the view in which the call was made (perhaps the view on the top of the screen has a height of 260). If you are trying to use getX() or getY() to calculate the middle of the screen then you would have to take all sizes of all views into consideration but I think you want to use getRawX() and getRawY()
An angle of 0 degrees correspond to the geometric angle of 0 degrees (3 o'clock on a watch.)
try using translate to translate the co-ordinates to top of the screen.
http://developer.android.com/reference/android/graphics/Canvas.html#translate(float, float)

Zoom in images with their layout

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

Android listview scroll by pixels with no delay

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);

Categories

Resources