在android中动画两个ImageViews

时间:2015-09-23 12:29:57

标签: android animation android-imageview

我在主线性布局中有两个线性布局,我设置了两个线性布局背景图像。现在我想逐个显示两个图像。第一张图像应慢慢显示淡入淡出动画;完成此操作后,第二张图像也应该以淡入淡出的动画显示。我怎样才能做到这一点?我的代码和屏幕截图如下。提前谢谢。

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_weight="15"
        android:id="@+id/L1"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@drawable/b2">
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#ffffffff" />

    <LinearLayout
        android:layout_weight="85"
        android:id="@+id/L2"
        android:orientation="vertical"`
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@drawable/b1">
    </LinearLayout>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

程序化解决方案(用Java编写):

ObjectAnimator animPic1 = ObjectAnimator.ofFloat(viewL1, "alpha", 0f, 1f);
ObjectAnimator animPic2 = ObjectAnimator.ofFloat(viewL2, "alpha", 0f, 1f);
AnimatorSet animSet = new AnimatorSet();
animSet.playSequentially(animPic1, animPic2);
animSet.start();

另一种方法是在XML资源文件中定义动画,加载它们并将它们应用到所需的视图对象。可以在http://blog.stylingandroid.com/simple-animation-part-1/

找到对android中这些基本动画的一个很好的介绍