[英]Android - animate view from RelativeLayout to sibling Relativeayout
My Activity
has a RelativeLayout
as it's main view with the id parent
. 我的
Activity
有一个RelativeLayout
作为其主视图,其ID为parent
。 Within this I have two RelativeLayouts
, child1
and child2
. 在其中,我有两个
RelativeLayouts
, child1
和child2
。
I want to animate an ImageView
from child2 RelativeLayout
to child1
. 我想为从
child2 RelativeLayout
到child1
的ImageView
设置动画。 I don't want the image to disappear in child2
to then suddenly appear in 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>
I can't find anyway of doing this without using addView
and removeView
. 如果不使用
addView
和removeView
我将无法找到任何removeView
。 If I do this though, the ImageView
will just appear in child1
, and I won't be able to animate it smoothly. 但是,如果执行此操作,则
ImageView
只会出现在child1
,并且我将无法对其进行动画处理。
I have the idea of the following possible way but it feels like a real long winded hack. 我有以下几种可能的想法,但感觉就像是一个漫长的。
x
and y
of the ImageView
ImageView
的x
和y
parent
parent
添加重复视图 child2
child2
移除原件 parent
to the correct position in child1
(which will require potentially difficult calculations) parent
项中的重复项动画child1
的正确位置(这可能需要潜在的困难计算) child1
which is underneath the duplicate view child1
添加原始视图,该视图位于重复视图的下面 Is there any other way of doing this? 还有其他方法吗?
For a simple way you can try like this : 您可以尝试使用以下简单方法:
<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>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image2"
android:layout_centerInParent="true"/>
</RelativeLayout>
<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/image2"
android:layout_centerInParent="true"
android:visibility:gone/>
</RelativeLayout>
</RelativeLayout>
and in Java when button is pressed for example, just add drawable to "image2", set visible "image2" and hide "image1". 例如在Java中,当按下按钮时,只需将drawable添加到“ image2”,设置可见的“ image2”并隐藏“ image1”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.