Reputation: 490
I've a TextView in my app and I want it to rotate from left edge along Y-Axis.
Using this code,
<rotate
android:fromDegrees="90"
android:toDegrees="0"
android:pivotX="0%"
android:pivotY="0%"
android:duration="2000" />
I'm able to make it rotate along the left edge, but it does not move along Y-Axis.
However, when I use objectAnimator, it does move along Y-Axis using its rotationY property, but then, I cannot set the values pivotX and pivotY which makes it to rotate along the centre rather than from the left edge.
How do I achieve both the things at the same time?
Please help me!!
Thanks in advance.
Upvotes: 1
Views: 6329
Reputation: 9142
You can use setRotationY() method to ratate around the y axis.
ValueAnimator lockAnimator = ValueAnimator.ofFloat(0, 1); // value from 0 to 1
lockAnimator.setDuration(ANIMATION_DURATION);
lockAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator pAnimation) {
float value = (Float) (pAnimation.getAnimatedValue());
textView.setRotationY(180 * value);
}
});
Upvotes: 0
Reputation: 175
To rotate view from left edge, try using the following property of view.
android:transformPivotX = "0dp"
This will rorate your view from left edge.
Upvotes: 0
Reputation: 423
check this card flip animation from android. basicly you define 4 animations and set the animation order with
getFragmentManager()
.beginTransaction()
.setCustomAnimations(
R.animator.card_flip_right_in, R.animator.card_flip_right_out,
R.animator.card_flip_left_in, R.animator.card_flip_left_out)
.replace(R.id.container, new CardBackFragment())
.addToBackStack(null)
.commit();
you might want to change the angles and "valueFrom", "valueTo" properties to fit your needs.
Upvotes: 2