Android ObjectAnimator Rotation is cropping the view
up vote
0
down vote
favorite
I have a custom view which is simulating the rotation of a ball with some text.
To achieve this, my custom view( which extends RelativeLayout) is overriding the onDraw method:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mCirclePath.reset();
mCirclePath.addCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, mRadious, Path.Direction.CW);
canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, mRadious, mBackGroundPaint);
canvas.drawPath(mCirclePath, mBackGroundPaint);
canvas.clipPath(mCirclePath);
canvas.drawColor(Color.TRANSPARENT);
}
This way I'm cropping everything outside of the bitmap circumference, allowing me to move the text inside the layout. this + rotating the text simulates the ball rotation in fake 3d.
My solution works fine in Android 4,5,6 and 9, but somehow it's not working in 7 and 8.
Here is a very simplify version of my animation with just the view rotation part:
ObjectAnimator anim = ObjectAnimator.ofFloat(this, View.ROTATION, 0, 190);
anim.setDuration(6000);
In Android 7 and 8 it seems like the bitmap and the text view are rotating but the container remains static. this works perfectly in other android versions...
I already tried moving the camera position wit no success.
Edit1: So after messing around for a while i found that the culprit is clipPath, somehow this conflicts with the Object animator rotation. the "solution" i found for now, is setting the LayerType to View.LAYER_TYPE_SOFTWARE. But i'm not happy with this solution because since this is a composite view, and I'm animating the text at the same time, the layer is going to keep invalidating...
canvas rotation crop objectanimator clip-path
add a comment |
up vote
0
down vote
favorite
I have a custom view which is simulating the rotation of a ball with some text.
To achieve this, my custom view( which extends RelativeLayout) is overriding the onDraw method:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mCirclePath.reset();
mCirclePath.addCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, mRadious, Path.Direction.CW);
canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, mRadious, mBackGroundPaint);
canvas.drawPath(mCirclePath, mBackGroundPaint);
canvas.clipPath(mCirclePath);
canvas.drawColor(Color.TRANSPARENT);
}
This way I'm cropping everything outside of the bitmap circumference, allowing me to move the text inside the layout. this + rotating the text simulates the ball rotation in fake 3d.
My solution works fine in Android 4,5,6 and 9, but somehow it's not working in 7 and 8.
Here is a very simplify version of my animation with just the view rotation part:
ObjectAnimator anim = ObjectAnimator.ofFloat(this, View.ROTATION, 0, 190);
anim.setDuration(6000);
In Android 7 and 8 it seems like the bitmap and the text view are rotating but the container remains static. this works perfectly in other android versions...
I already tried moving the camera position wit no success.
Edit1: So after messing around for a while i found that the culprit is clipPath, somehow this conflicts with the Object animator rotation. the "solution" i found for now, is setting the LayerType to View.LAYER_TYPE_SOFTWARE. But i'm not happy with this solution because since this is a composite view, and I'm animating the text at the same time, the layer is going to keep invalidating...
canvas rotation crop objectanimator clip-path
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a custom view which is simulating the rotation of a ball with some text.
To achieve this, my custom view( which extends RelativeLayout) is overriding the onDraw method:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mCirclePath.reset();
mCirclePath.addCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, mRadious, Path.Direction.CW);
canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, mRadious, mBackGroundPaint);
canvas.drawPath(mCirclePath, mBackGroundPaint);
canvas.clipPath(mCirclePath);
canvas.drawColor(Color.TRANSPARENT);
}
This way I'm cropping everything outside of the bitmap circumference, allowing me to move the text inside the layout. this + rotating the text simulates the ball rotation in fake 3d.
My solution works fine in Android 4,5,6 and 9, but somehow it's not working in 7 and 8.
Here is a very simplify version of my animation with just the view rotation part:
ObjectAnimator anim = ObjectAnimator.ofFloat(this, View.ROTATION, 0, 190);
anim.setDuration(6000);
In Android 7 and 8 it seems like the bitmap and the text view are rotating but the container remains static. this works perfectly in other android versions...
I already tried moving the camera position wit no success.
Edit1: So after messing around for a while i found that the culprit is clipPath, somehow this conflicts with the Object animator rotation. the "solution" i found for now, is setting the LayerType to View.LAYER_TYPE_SOFTWARE. But i'm not happy with this solution because since this is a composite view, and I'm animating the text at the same time, the layer is going to keep invalidating...
canvas rotation crop objectanimator clip-path
I have a custom view which is simulating the rotation of a ball with some text.
To achieve this, my custom view( which extends RelativeLayout) is overriding the onDraw method:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mCirclePath.reset();
mCirclePath.addCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, mRadious, Path.Direction.CW);
canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, mRadious, mBackGroundPaint);
canvas.drawPath(mCirclePath, mBackGroundPaint);
canvas.clipPath(mCirclePath);
canvas.drawColor(Color.TRANSPARENT);
}
This way I'm cropping everything outside of the bitmap circumference, allowing me to move the text inside the layout. this + rotating the text simulates the ball rotation in fake 3d.
My solution works fine in Android 4,5,6 and 9, but somehow it's not working in 7 and 8.
Here is a very simplify version of my animation with just the view rotation part:
ObjectAnimator anim = ObjectAnimator.ofFloat(this, View.ROTATION, 0, 190);
anim.setDuration(6000);
In Android 7 and 8 it seems like the bitmap and the text view are rotating but the container remains static. this works perfectly in other android versions...
I already tried moving the camera position wit no success.
Edit1: So after messing around for a while i found that the culprit is clipPath, somehow this conflicts with the Object animator rotation. the "solution" i found for now, is setting the LayerType to View.LAYER_TYPE_SOFTWARE. But i'm not happy with this solution because since this is a composite view, and I'm animating the text at the same time, the layer is going to keep invalidating...
canvas rotation crop objectanimator clip-path
canvas rotation crop objectanimator clip-path
edited Nov 20 at 1:10
asked Nov 19 at 22:04
Katazo
305
305
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383295%2fandroid-objectanimator-rotation-is-cropping-the-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown