我有一个int rotation = this.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break;
case Surface.ROTATION_90: degrees = 90; break;
case Surface.ROTATION_180: degrees = 180; break;
case Surface.ROTATION_270: degrees = 270; break;
}
int relative_orientation = (current_orientation + degrees) % 360;
int ui_rotation = (360 - relative_orientation) % 360;
preview.setUIRotation(ui_rotation);
,当手机旋转时会旋转。它按照设备方向旋转。类似的东西:
ImageButton
然后在view = findViewById(R.id.button1);
layoutParams = (RelativeLayout.LayoutParams)view.getLayoutParams();
view.setLayoutParams(layoutParams);
view.setRotation(ui_rotation);
我这样做:
void setUIRotation(int ui_rotation) {
if( MyDebug.LOG )
Log.d(TAG, "setUIRotation");
this.ui_rotation = ui_rotation;
}
它有效,但没有动画..所以旋转非常剧烈而且不平滑..有没有办法放动画?
编辑:我添加了setUIRotation()方法
text-overflow: ellipsis
答案 0 :(得分:0)
您可以使用类似这样的内容而不是view.setRotation()
:
RotateAnimation rotate = new RotateAnimation(0f, ui_rotation,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(500);
rotate.setFillAfter(true);
view.startAnimation(rotate);
对于边缘情况,例如当触发另一个旋转时,动画尚未结束,您可以使用setAnimationListener
获得更好的效果。
您可以参考Rotating a view in Android的讨论了解详情。