在LinearLayout中旋转视图的问题

3

我有一个线性布局,其方向为垂直,在该布局内有三个按钮(确切地说是ImageButtons),当方向改变时(通过OrientationEventListener),它们会进行旋转动画。顶部和底部的按钮旋转得很完美,但中间的按钮却没有。它似乎偏离了旋转中心点。

以下是动画的布局:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0" 
    android:toDegrees="-90"
    android:pivotX="50%" 
    android:pivotY="50%"
    android:duration="500"/>

这是我启动动画的方式:

Animation rotate = AnimationUtils.loadAnimation(this.mContext, animResId);
rotate.setFillEnabled(true);
rotate.setFillAfter(true);
{...retrieve the each ImageButton then call startAnimation(rotate) on them...}

这是我活动中组件的布局,它是我的菜单LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/camera_menu"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/camera_preview"
    android:layout_alignParentRight="true"
    >
    <ImageButton
            android:id="@+id/camera_top_button"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="3"
            android:src="@drawable/placeholder"
            android:scaleType="centerInside"
            android:onClick="onTopButtonClick"
    />
    <ImageButton
            android:id="@+id/camera_action_button"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="2"
            android:src="@drawable/placeholder"
            android:scaleType="centerInside"
            android:onClick="onActionButtonClick"
    />
    <ImageButton
            android:id="@+id/camera_bottom_button"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="3"
            android:src="@drawable/placeholder"
            android:scaleType="centerInside"
            android:onClick="onBottomButtonClick"
    />
</LinearLayout>

有人知道为什么中间的(动作)按钮没有围绕正确的旋转中心旋转吗?

我注意到的一件事是,在旋转之后,中间的按钮与其他两个较小的按钮(顶部和底部按钮)的顶部对齐。

感谢您提前的任何帮助!

祝好,celestialorb。


我也遇到了关于数据透视表的问题。我开始怀疑这是一个错误。你解决了这个问题吗? - Thomas
1个回答

1
这只是一个简单的观察,但你考虑过 layout_weight 属性是否是罪魁祸首吗?由于它有不同的权重,可能会在旋转时重新调整大小并做一些奇怪的事情。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接