【发布时间】:2013-09-05 06:49:48
【问题描述】:
我有一个垂直的线性布局,在线性布局中有三个可点击的图像视图。当我使用简单的动画将线性布局旋转 90 度时,问题就出现了。图像视图已正确旋转,但图像视图的 onclick 事件不会与线性布局一起旋转,并且与动画之前一样保持在原始位置。
下面是我的主要java代码
westplayer = (LinearLayout) findViewById(R.id.linearLayout_west);
// Create an animation instance
Animation an = new RotateAnimation(0.0f, 180.0f, 32, 180);
// Set the animation's parameters
an.setDuration(0); // duration in ms
an.setRepeatCount(0); // -1 = infinite repeated
an.setRepeatMode(Animation.REVERSE); // reverses each repeat
an.setFillAfter(true); // keep rotation after animation
// Apply animation to linearlayout
westplayer.setAnimation(an);
上面的代码处理动画部分。下面的代码跟随动画,并用于更新布局位置,但不适用于我。
// Update Layout
int top=westplayer.getTop();
int bottom=westplayer.getBottom();
int left=westplayer.getLeft();
int right=westplayer.getRight();
westplayer.layout(left, top , right, bottom );
xml如下:
<LinearLayout
android:id="@+id/linearLayout_west"
android:layout_width="42dp"
android:layout_height="250dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/linearLayout_north"
android:duplicateParentState="false"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageViewW1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/spades_14"
/>
<ImageView
android:id="@+id/imageViewW2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/spades_14"
android:layout_marginTop="-15dp"
/>
<ImageView
android:id="@+id/imageViewW3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/spades_14"
android:layout_marginTop="-15dp"
/>
</LinearLayout>
我从this 获得了更新布局代码,还找到了另一个我也尝试过this 的解决方案,但仍然没有积极的结果。我需要它来为 API 10 工作。非常感谢任何帮助
【问题讨论】:
-
这个图像视图是线性布局的子级吗?
-
是的,它是线性布局的子,我已经添加了上面的xml代码。
标签: android android-layout rotation android-linearlayout android-view