【发布时间】:2014-08-16 18:14:21
【问题描述】:
我的Activity 有一个RelativeLayout 作为主视图,ID 为parent。其中我有两个RelativeLayouts、child1 和child2。
我想将ImageView 从child2 RelativeLayout 动画化到child1。我不希望图像在child2 中消失然后突然出现在child1 中。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/child1"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/child2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image"
android:layout_centerInParent="true"/>
</RelativeLayout>
</RelativeLayout>
如果不使用addView 和removeView,我无论如何都找不到这样做的。但是,如果我这样做,ImageView 只会出现在child1 中,我将无法流畅地对其进行动画处理。
我有以下可能的方法的想法,但感觉就像一个真正的长篇大论。
- 找到
ImageView的x和y - 在
parent中添加重复视图 - 从
child2中删除原件 - 将
parent中的副本动画到child1中的正确位置(这将需要潜在的困难计算) - 在复制视图下方的
child1中添加原始视图 - 删除重复视图
还有其他方法吗?
【问题讨论】:
标签: android android-layout android-animation android-relativelayout