我仍然是Android的新手,我正在尝试围绕它的死点枢轴点旋转布局。我已经确定布局具有相同的高度和宽度,但我简直无法理解,一旦我旋转,就会添加某种填充,因此旋转会以某种方式移动布局。
我做错了什么?
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<RelativeLayout
android:id="@+id/capture_menu_wrapper"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="@color/red">
<com.mycomp.custom.Fontastic
android:id="@+id/menu_icon_icon"
android:text="@string/ft_burger_menu_outlined"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_centerInParent="true"/>
</RelativeLayout>
</RelativeLayout>
和我的活动轮换部分:
private void rotateView(int oldOrientation, int orientation, View... views) {
/*
* If the current orientation is Inverted portrait, and the user changes to inverted
* landscape, (or vice versa) we have to make sure the animation rotates the right way
* otherwise the animation rotates 270 degrees to the new position, instead of only
* having to rotate 90 degrees.
*/
// PortraitInverted --> LandscapeInverted
if (oldOrientation == 180 && orientation == -90) oldOrientation = -180;
// LandscapeInverted --> PortraitInverted
else if (oldOrientation == -90 && orientation == 180) orientation = -180;
RotateAnimation rotate = new RotateAnimation(oldOrientation, orientation,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotate.setFillAfter(true);
rotate.setFillEnabled(true);
rotate.setDuration(400);
for (View v : views){
v.clearAnimation();
v.setAnimation(rotate);
}
}
编辑: 我尝试过的事情:
活动以纵向模式锁定。
答案 0 :(得分:0)
对于任何有相同问题的人,在闭包后运行setAnimation可以解决我这样的问题。