android - Android横向模式下的渲染问题
问题描述
我使用 View.setRotationY() 根据设备的方向旋转我的视图。纵向时一切正常。但是当设备旋转时,布局的背景会变形。
代码:
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
}
当我使用 View.setRotationY() 方法设置 -60 度和 -90 度之间的角度时,我希望背景看起来像0 ~ -60 中的这个角度。但是,结果是这个角度在 -60 ~ -90
同样,当我将角度设置在 75 度和 90 度之间时,我希望背景看起来像0 ~ 75 之间的这个角度。但是,原来这个角度在 75 ~ 90
我该如何纠正这个..?
解决方案
我从 GitHub 获得了一个想法——FlipViewPager。它使用“Camera”+“Matrix”而不是“setRotationY()”,例如:
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)
我将代码“mMatrix.preScale(0.25F, 0.25F) mMatrix.postScale(4F, 4F)”添加到我的程序中,它运行良好,没有渲染错误
推荐阅读
- python - 我无法在 pycharm 中安装 openpyxl
- string - pandas_datareader 在从雅虎获取股票拆分时出错
- github - 如何从 Github 存储库嵌入代码,就像你可以用 gist 做的那样?
- splunk - Citrix/COTS 应用程序监视器 - Splunk
- python - Pip 安装出错,退出状态为 1 [已解决]
- javascript - TypeError: this.props.nextStep 不是函数 React 错误
- c++ - 从 Arduino 上的多个模拟引脚读取输入的代码不会显示值
- c# - 如何用accord.net实现人脸识别?
- mysql - 如何通过Node JS在mysql数据库中存储和检索utf8字符
- java - Surefire 实际上并没有运行测试