java - 一个接一个地动画 View

标签 java android android-animation

我想为一些 TextViews 一个接一个地制作动画,就像 Google Now 应用程序中的卡片一样。我找到了这个 question我试着按照它的指示去做,但所有的动画都在同时播放。我做错了什么?

这是我要播放的动画:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator" >

    <translate
        android:duration="@integer/config_slide_time"
        android:fromYDelta="100%p"
        android:toYDelta="0" />

    <alpha
        android:duration="@integer/config_slide_time"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

    <rotate
        android:duration="@integer/config_slide_time"
        android:fromDegrees="25"
        android:pivotX="0"
        android:pivotY="0"
        android:toDegrees="0" />

</set>

这是我正在使用的布局:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.yai.properti.tujuh.tujuh.tujuh.ReadUserProfile$PlaceholderFragment" >

    <com.yai.app.animation.support.NowLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#e3e3e3"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/txtView"
            style="@style/nowCardStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="aaa"
            tools:context=".MainActivity" />

        <TextView
            android:id="@+id/txtView1"
            style="@style/nowCardStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="bbb"
            tools:context=".MainActivity" />

        <TextView
            android:id="@+id/txtView2"
            style="@style/nowCardStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="ccc"
            tools:context=".MainActivity" />

        <TextView
            android:id="@+id/txtView3"
            style="@style/nowCardStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="ddd"
            tools:context=".MainActivity" />

        <TextView
            android:id="@+id/txtView4"
            style="@style/nowCardStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="eee"
            tools:context=".MainActivity" />

    </com.yai.app.animation.support.NowLayout>

</RelativeLayout>

最佳答案

尝试遍历 Views 并使用 postDelayed() 启动 Animation,如下所示:

View[] views = new View[] { ... };

// 100ms delay between Animations
long delayBetweenAnimations = 100; 

for(int i = 0; i < views.length; i++) {
    final View view = views[i];

    // We calculate the delay for this Animation, each animation starts 100ms 
    // after the previous one
    long delay = i * delayBetweenAnimations;

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            Animation animation = AnimationUtils.loadAnimation(context, R.anim.your_animation);    
            view.startAnimation(animation);
        }
    }, delay);
}

关于java - 一个接一个地动画 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24889019/

相关文章:

android - 是否可以有两个相同 Eclipse 版本的不同实例?

android - 如何制作将周围物体吹走的爆炸动画?

java - 特定的正则表达式模式

android - 获取 StreamCorruptedException

java - 为什么当我尝试启动新 Intent 时会出现异常?

android - 如何设置弹出日历的EditText以选择日期并显示在Tab Activity的EditText中

android View 在动画之前暂时显示在最终位置

android - 列数更改时动画回收器 View 网格

java - jackson-all 和 jackson-mapper-asl 的最新 jar 版本是什么?

java - Spring:在语言环境 'en_US' 的代码下找不到消息