在android图像滑动动画中需要帮助

时间:2021-12-01 07:17:40

I am doing an app related to transportation.so i need to animate the image of a bus from left to right (coming from left stops at center and exit from the center to right) i want to repeat this animation until my splash screen ends.this is like what red bus uses when loading another activity.can you help me with the code?

我正在做一个与transport相关的应用程序。所以我需要从左到右动画公交车的图像(来自中间左边的停靠点,从中心到右边退出)我想重复这个动画,直到我的闪屏结束。这就像红色巴士在加载另一个活动时使用的那样。你帮我解决了这个问题吗?

I tried this but its giving wrong output

我尝试了这个,但它给出了错误的输出

<animation-list
xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
<item android:drawable="@drawable/sp1" android:duration="1000"/>
<item android:drawable="@drawable/sp2" android:duration="1000" />
<item android:drawable="@drawable/sp3" android:duration="1000" />
<item android:drawable="@drawable/sp4" android:duration="1000" />

and this in main

这主要是

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.splash);
    ImageView mMailTab = (ImageView)findViewById(R.id.splash_view);
    mMailTab.setImageBitmap(null);
    mMailTab.setBackgroundResource( R.anim.splash_anim );

    final AnimationDrawable mailAnimation = (AnimationDrawable) mMailTab.getBackground();
    mMailTab.post(new Runnable() {
        @Override
        public void run() {
            if ( mailAnimation != null ) mailAnimation.start();
          }
    });

1 个解决方案

#1


here is The Code use This ...... First Create A Folder in like res/animation Then Create an xml ie move.xml

这里是代码使用这......首先在res / animation中创建一个文件夹然后创建一个xml即move.xml

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

    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXDelta="-75%p"
        android:toXDelta="75%p" >
    </translate>
    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXDelta="-75%p"
        android:startOffset="800"
        android:toXDelta="75%p" >
    </translate>

</set>

Then to apply use this

然后申请使用这个

Animation animation = AnimationUtils.loadAnimation(
            getApplicationContext(), R.animation.move);
    animation.setDuration(yourTime);
    imageView.startAnimation(animation);

#1


here is The Code use This ...... First Create A Folder in like res/animation Then Create an xml ie move.xml

这里是代码使用这......首先在res / animation中创建一个文件夹然后创建一个xml即move.xml

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

    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXDelta="-75%p"
        android:toXDelta="75%p" >
    </translate>
    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXDelta="-75%p"
        android:startOffset="800"
        android:toXDelta="75%p" >
    </translate>

</set>

Then to apply use this

然后申请使用这个

Animation animation = AnimationUtils.loadAnimation(
            getApplicationContext(), R.animation.move);
    animation.setDuration(yourTime);
    imageView.startAnimation(animation);