-1

I use View.setRotationY() to rotate my views according to the orientation of the device. Everything works well while in portrait. But when the device is rotated, the layout's background gets distorted.

code:

if(under == RecyclerView.NO_POSITION){
        aboveBinding.vContainerLeft.rotationY = 0F
        aboveBinding.vContainerRight.rotationY = 0F
    }else if(under == above - 1){
        val half = width / 2
        val degrees = 90 * ((width - offset).toFloat() / half)
        aboveBinding.vContainerLeft.pivotX = aboveBinding.vContainerLeft.width.toFloat()
        aboveBinding.vContainerLeft.rotationY = degrees
        aboveBinding.vContainerRight.rotationY = 0F
    }else{
        val half = width / 2
        val degrees = -90 * (offset.toFloat() / half)
        aboveBinding.vContainerRight.pivotX = 0F
        aboveBinding.vContainerLeft.rotationY = 0F
        aboveBinding.vContainerRight.rotationY = degrees
    }

When I use View.setRotationY() method to set the angle between -60 deg and -90 deg, I expect the background to look like thisangle in 0 ~ -60. But, it turns out like thisangle in -60 ~ -90

Again, when I set the angle between 75 deg and 90 deg, I expect the background to look like thisangle in 0 ~ 75. But, it turns out like thisangle in 75 ~ 90

How do I rectify this..?

Jade
  • 416
  • 5
  • 7
  • the screenshots are not clear at all, try to post actual screenshots and a snippet of code that covers what exactly you're trying to do – y.allam Apr 23 '19 at 11:40
  • @y.allam thanks for your advice, I modified my question – Jade Apr 24 '19 at 02:22
  • this problem is also related to pivot of the View; when i use default pivot(center of the view), it will work well – Jade Apr 24 '19 at 02:27

1 Answers1

0

I get an idea from GitHub--FlipViewPager. it use "Camera" + "Matrix" instead of "setRotationY()", like:

canvas.save()
    mCamera.save()
    mCamera.rotateY(degreeRange * degRadio)
    mCamera.getMatrix(mMatrix)
    mMatrix.preScale(0.25F, 0.25F)
    mMatrix.postScale(4F, 4F)

    mMatrix.preTranslate(preDx, preDy)
    mMatrix.postTranslate(-preDx, -preDy)

    canvas.concat(mMatrix)

I add the code "mMatrix.preScale(0.25F, 0.25F) mMatrix.postScale(4F, 4F)" to my program, and it work well, without the render error

Jade
  • 416
  • 5
  • 7