额,先说下本文需求…
- 只能用manifests中的screenOrientation来设置屏幕方向为”landscape”
- 不能用代码setRequestedOrientation(..)来动态设置屏幕方向
- 然后根据需求来90度旋转屏幕!
那现在我就只能用 属性动画 了…大家有什么可以提出来哈
思路是旋转父布局 , 就会将里面的所有子布局也一并进行旋转并适应父布局
- 小插曲…我这子布局里有个VideoView…旋转后VideoView不能播放了,所有我用的是一个网路开源库https://github.com/sprylab/texturevideoview , 与VideoView一样的操作,就是可以旋转!
这里的思路主要就是通过属性动画,将布局中的父视图进行旋转操作!
- 1.参数 需要2个,angle (角度) 和 父布局
- 2.每次进行90 , 180 、270 、的旋转(90的倍数)
- 3.旋转后将宽高进行比例对换
public static void portrait1920_1080(int angle, View mbaseView) {
AnimatorSet set = new AnimatorSet();
ObjectAnimator a1 = ObjectAnimator.ofFloat(mbaseView, "rotation", 0f, angle);
ObjectAnimator a2 = null;
ObjectAnimator a3 = null;
if (angle == 90) {
a2 = ObjectAnimator.ofFloat(mbaseView, "scaleX", 9f / 16f, 1f);
a3 = ObjectAnimator.ofFloat(mbaseView, "scaleY", 16f / 9f, 1f);
}
if (angle == 180) {
a2 = ObjectAnimator.ofFloat(mbaseView, "scaleX", 1f, 9f / 16f);
a3 = ObjectAnimator.ofFloat(mbaseView, "scaleY", 1f, 16f / 9f);
}
if (angle == 270) {
a2 = ObjectAnimator.ofFloat(mbaseView, "scaleX", 9f / 16f, 1f);
a3 = ObjectAnimator.ofFloat(mbaseView, "scaleY", 16f / 9f, 1f);
}
if (angle == 360) {
a2 = ObjectAnimator.ofFloat(mbaseView, "scaleX", 1f, 16f / 9f);
a3 = ObjectAnimator.ofFloat(mbaseView, "scaleY", 1f, 9f / 16f);
}
if (a2 == null || a3 == null) {
set.playTogether(a1);
} else {
set.playTogether(a1, a2, a3);
}
set.setDuration(300).start();
if (a2 != null && a3 != null) {
a2.cancel();
a3.cancel();
}
}
- 将父布局旋转后, 在将他的X轴 和 Y轴 进行比例对换….. 恩 这是自己的想法 , 如果大家有别的想法希望提出来哈 或者根据这个提出小问题,我不一定会 嘎嘎
2.恩 之前一哥们说这是博客??…我不知道博客的定义是什么…这个算是自己在项目的总结吧,虽然只是一个方法而已…总比写在笔记本上好啊 嘿嘿 (反正我是初级人员)