Android ObjectAnimator Rotation is cropping the view












0















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...
enter image description here



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...










share|improve this question





























    0















    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...
    enter image description here



    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...










    share|improve this question



























      0












      0








      0








      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...
      enter image description here



      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...










      share|improve this question
















      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...
      enter image description here



      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 1:10







      Katazo

















      asked Nov 19 '18 at 22:04









      KatazoKatazo

      355




      355
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          How to send String Array data to Server using php in android

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Is anime1.com a legal site for watching anime?