Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 一个接一个地为视图设置动画_Java_Android_Android Animation - Fatal编程技术网

Java 一个接一个地为视图设置动画

Java 一个接一个地为视图设置动画,java,android,android-animation,Java,Android,Android Animation,我想一个接一个地制作一些文本视图的动画,就像GoogleNow应用程序中的卡片一样。我发现了这个,我试着按照它的指示,但所有的动画都在同一时间播放。我做错了什么 这是我要播放的动画: <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accele

我想一个接一个地制作一些
文本视图的动画,就像GoogleNow应用程序中的卡片一样。我发现了这个,我试着按照它的指示,但所有的动画都在同一时间播放。我做错了什么

这是我要播放的动画:

<?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>

尝试实现animationListener

对每个文本视图都这样做

  @Override
    public void onAnimationEnd(Animation animation) {
        another_text.startAnimation(animation1);

    }

尝试循环查看
视图
,然后使用
postDelayed()
启动
动画
,如下所示:

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

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

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
    int delay = i * delayBetweenAnimations;

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            Animation animation = AnimationUtils.loadAnimation(context, R.anim.your_animation);    
            view.startAnimation(animation);
        }
    }, delay);
}
new AnimationUtils();
Animation anim_one= AnimationUtils.loadAnimation(this,  R.anim.anim1);
Animation anim_two = AnimationUtils.loadAnimation(this, R.anim.anim2);
txt1.startAnimation(anim_one);
txt2.startAnimation(anim_two);
View[]views=新视图[]{…};
//动画之间的延迟为100毫秒
长延时间隔时间=100l;
对于(int i=0;i
也许这不是一个标准的方法,但它比其他答案更适合我。 我为每个视图制作一个动画资源文件,我想在每个视图之后制作动画,并给每个下一个动画更多的持续时间。 例如,如果我们有三个文本视图,我们希望在彼此之后从右向左设置动画,我们将创建两个anim file.xml,如下所示:

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

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

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
    int delay = i * delayBetweenAnimations;

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            Animation animation = AnimationUtils.loadAnimation(context, R.anim.your_animation);    
            view.startAnimation(animation);
        }
    }, delay);
}
new AnimationUtils();
Animation anim_one= AnimationUtils.loadAnimation(this,  R.anim.anim1);
Animation anim_two = AnimationUtils.loadAnimation(this, R.anim.anim2);
txt1.startAnimation(anim_one);
txt2.startAnimation(anim_two);
anim1.xml:

<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="500"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="0"
android:duration="1000">

</translate>

要为视图设置动画,我们希望视图不可见,并随动画变为可见,对吗

我就是这样做到的

             int i = 0;
             long delayBetweenAnimations = 100L;

             while (viewsContainer.getChildAt(i) != null) {
                final View v = viewsContainer.getChildAt(i);
                v.setVisibility(View.Gone);                 //make the view invisible because the animation will take time to start
                i++; 
                long delay = i * delayBetweenAnimations;   //increase the delay time so each view's animation take longer time.

                    v.postDelayed(new Runnable() {
                        @Override
                        public void run() { 
                            v.setVisibility(View.VISIBLE);   //make the view visible now
                            Animation animation = AnimationUtils.loadAnimation(context, R.anim.lefttoright);
                            v.startAnimation(animation);
                        }
                    }, delay);
            }