0

我对 Droid 还很陌生,我一直在绞尽脑汁想弄清楚如何创建这个动画循环,我希望它看起来像这样......

3张动画图像

我一直在尝试创建 3 个背靠背的平移动画,它们会不断地向右滑动。我可以让第一个 imageview 像我想要的那样制作动画,但是我很难为我的代码添加什么来让其他动画也能在它后面制作动画

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView image1 = (ImageView) findViewById(R.id.nescontroller);
ImageView image2 = (ImageView) findViewById(R.id.segacontroller);
ImageView image3 = (ImageView) findViewById(R.id.pscontroller);

TranslateAnimation anim1 = new TranslateAnimation(0, 500, 0, 0);
anim1.setDuration(2000);
anim1.setRepeatCount(Animation.INFINITE);

image1.startAnimation(anim1);


<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"
tools:context=".MainActivity" >

    <ImageView
    android:id="@+id/ee"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/e" />

    <ImageView
    android:id="@+id/dd"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/d" />

    <ImageView
    android:id="@+id/pscontroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/c" />

    <ImageView
    android:id="@+id/segacontroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/b" />

    <ImageView
    android:id="@+id/nescontroller"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/a" />
</RelativeLayout>

任何帮助或建议将不胜感激

4

1 回答 1

0

好的,我很难过没有人能帮我解决这个问题,但经过一个月的不幸搜索和挖掘,我找到了一种方法。

我想出了如何正确使用 Animationlistener,我还没有弄清楚如何最初启动animationlistener,所以我只是使用了一个虚拟动画来启动循环,它只持续一毫秒离开屏幕。

我还添加了一些小的过渡动画,以便每个新的重叠图像同时显示,重叠图像移出屏幕,而不是在完全移出屏幕后出现:-)

ImageView image0 = (ImageView) findViewById(R.id.splashimage)
ImageView image1 = (ImageView) findViewById(R.id.nescontroller);
ImageView image2 = (ImageView) findViewById(R.id.segacontroller);
ImageView image3 = (ImageView) findViewById(R.id.pscontroller);

anim0 = new TranslateAnimation(400.0f, 400.0f, 0.0f, 0.0f);
    anim0.setDuration(1);
    img0.startAnimation(anim0);

anim1 = new TranslateAnimation(0.0f, 400.0f, 0.0f, 0.0f);
    anim1.setStartOffset(2000);
    anim1.setDuration(2000);
    anim1.setFillAfter(true);

anim2 = new TranslateAnimation(0.0f, 400.0f, 0.0f, 0.0f);
    anim2.setStartOffset(2000);
    anim2.setDuration(2000);
    anim2.setFillAfter(true);

anim3 = new TranslateAnimation(0.0f, 400.0f, 0.0f, 0.0f);
    anim3.setStartOffset(2000);
    anim3.setDuration(2000);
    anim3.setFillAfter(true);

stationary1 = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
stationary1.setDuration(4000);
stationary1.setFillAfter(true);

stationary2 = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
stationary2.setDuration(4000);
stationary2.setFillAfter(true);

stationary3 = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
stationary3.setDuration(4000);
stationary3.setFillAfter(true);

anim0.setAnimationListener (new AnimationListener() {
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub 
            }
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub
            }
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
        img1.startAnimation(anim1);
        img2.startAnimation(stationary1);


    }
});

anim1.setAnimationListener (new AnimationListener() {
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub 

        }
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
        }
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
        img2.startAnimation(anim2);
        img3.startAnimation(stationary2);

    }
});

anim2.setAnimationListener(new AnimationListener() {
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub 
        }
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
        }
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
        img3.startAnimation(anim3);
        img1.startAnimation(stationary3);

    }
});
anim3.setAnimationListener(new AnimationListener() {
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub 
        }
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
        }
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
        img1.startAnimation(anim1);
        img2.startAnimation(stationary1);


    }
});
于 2013-11-14T00:38:36.757 回答