LinearLayout 问题中的旋转视图
我有一个垂直方向的 LinearLayout,在该布局中我有三个按钮(确切地说是 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>
有谁知道为什么中间(操作)按钮没有围绕正确的枢轴点旋转?
我注意到的一件事是,旋转后,中间按钮与其他两个较小按钮(顶部和底部按钮)的顶部对齐。
预先感谢您的任何帮助!
问候,天球。
I have a LinearLayout with a vertical orientation, within that layout I have three buttons (ImageButtons to be exact) and when the orientation changes (via an OrientationEventListener) I have them set to perform a rotation animation. The top and bottom buttons rotate perfectly, however the middle one does not. Its pivot point seems to be off.
Here is the layout of the animation:
<?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"/>
...and here is how I initiate the animation:
Animation rotate = AnimationUtils.loadAnimation(this.mContext, animResId);
rotate.setFillEnabled(true);
rotate.setFillAfter(true);
{...retrieve the each ImageButton then call startAnimation(rotate) on them...}
...and here is the layout for the component in my activity that is the LinearLayout for my menu:
<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>
Does anyone have an idea as to why the middle (action) button is not rotating around the correct pivot point?
One thing I have noticed is that after rotating, the middle button is aligned with the tops of the other two, smaller buttons (the top and bottom buttons).
Thanks in advance for any help!
Regards, celestialorb.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这只是一个简单的观察,但是您是否认为
layout_weight
属性是罪魁祸首?由于它具有不同的重量,因此可能会调整旋转大小并做一些奇怪的事情。This is just a simple observation, but have you considered the
layout_weight
attribute to be the culprit? Since it has a different weight it could be resizing on the rotation and doing some weird things.