我正在尝试使用AnimationSet实现翻译和缩放动画。
这就是我想要实现的目标
img1,2,3是我想要缩放的图像(原始大小为小)并将其全部翻译为屏幕的一个位置。
img4是一个大图像,它在自己的位置上淡入,在所有img1,2,3比例中,转换到新的位置,img4淡入并显示在该位置
我的xml布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="100"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="80" >
<ImageView
android:id="@+id/imageview1"
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/wedding_normal" />
<ImageView
android:id="@+id/imageview2"
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/wedding_normal" />
<ImageView
android:id="@+id/imageview3"
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/wedding_normal" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20" >
</LinearLayout>
</LinearLayout>
我正在使用的代码
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView iv1 = (ImageView) findViewById(R.id.imageview1);
final int amountToMoveRight = 200;
final int amountToMoveDown = 700;
AnimationSet animSet = new AnimationSet(true);
animSet.setFillAfter(true);
animSet.setDuration(5000);
TranslateAnimation anim = new TranslateAnimation(0, amountToMoveRight,
0, amountToMoveDown);
anim.setFillAfter(true);
animSet.addAnimation(anim);
ScaleAnimation scale = new ScaleAnimation(1f, 1f, 1f, 0.5f,
Animation.RELATIVE_TO_SELF, (float) 1,
Animation.RELATIVE_TO_SELF, (float) 0.5);
scale.setFillAfter(true);
animSet.addAnimation(scale);
iv1.startAnimation(animSet);
}
}
我能够正确翻译,但我无法正确制作缩放动画