如何出来,淡入两个图像之间?图像、两个

2023-09-05 01:10:29 作者:清新不如倾心

好一点帮助在这里,所以我有两个图像加载在我的启动画面。第一个图像打开(启动闪屏),那么第二个图像打开,一旦第二图像关闭mainactivity开始。现在的问题是如何让我的第一个图像淡出,然后淡入我的第二个形象?

哦,是的,没有交叉淡入淡出 - 仅仅一个完整的淡出和经济转型 提前 - 谢谢

-The splash.xml

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =中心
机器人:ID =@ + ID / lin_lay
机器人:重力=中心>

< ImageView的
机器人:contentDescription =@字符串/递减
机器人:方向=横向
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / spinning_wheel_image
机器人:背景=@可绘制/ splashscreen1/>
< / LinearLayout中>
 

在mainanim.xml

 <动画列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:单稳=假>
<项目机器人:可绘制=@可绘制/ splashscreen1机器人:时间=2500/>
<项目机器人:可绘制=@可绘制/ splashscreen2机器人:时间=4000/>
< /动画列表>
 

在Splash.java

  @覆盖
保护无效的onCreate(包savedInstanceState){
    // TODO自动生成方法存根
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.splash);
    ourSong = MediaPlayer.create(Splash.this,R.raw.splashsound);
    ourSong.start();
    螺纹定时器=新的Thread(){
        公共无效的run(){
            尝试{
                睡眠(10500);
            }赶上(InterruptedException异常E){
                e.printStackTrace();
            }最后{
                意图openStartingPoint =新的意向书(com.theapplication.app.STARTINGPOINT);
                startActivity(openStartingPoint);

            }
        }
    };
    timer.start();
}

@覆盖
公共无效setRequestedOrientation(INT requestedOrientation){
    // TODO自动生成方法存根
    super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

}

@覆盖
公共无效onWindowFocusChanged(布尔hasFocus){
    // TODO自动生成方法存根
    super.onWindowFocusChanged(hasFocus);
    ImageView的mainimage =(ImageView的)findViewById(R.id.spinning_wheel_image);
    mainimage.setBackgroundResource(R.anim.mainamin);
    mainanimation =(AnimationDrawable)mainimage.getBackground();
    mainanimation.start();
 
flash做一个图片淡入淡出怎么做.补间动画怎么做

解决方案

使用 ImageSwitcher 而不是的ImageView 支持动画由它的自我。 看到这样的例子:

http://www.java2s.com/$c$c/Android/UI/UsingImageSwitcher.htm

您可以添加动画是这样的:

  imageSwitcher.setInAnimation(fadeInAnimation);
imageSwitcher.setOutAnimation(fadeOutAnimation);
 

// 我的测试:

 公共类IntroActivity扩展活动实现的ViewFactory {

        私有静态最后字符串变量=IntroActivity;

        私人最终诠释[]的图像= {R.drawable.img3,R.drawable.img2,
            R.drawable.img1,R.drawable.img4,R.drawable.img5,R.drawable.img6,
            R.drawable.img7,R.drawable.img8};
    私人诠释指数= 0;
    私人最终诠释间隔= 10000;
    私人布尔isRunning = TRUE;

    @覆盖
    公共无效的onCreate(束捆){
        super.onCreate(包);
        的setContentView(R.layout.activity_intro);

        startAnimatedBackground();

    }

    私人无效startAnimatedBackground(){
        动画aniIn = AnimationUtils.loadAnimation(这一点,
                android.R.anim.fade_in);
        aniIn.setDuration(3000);
        动画aniOut = AnimationUtils.loadAnimation(这一点,
                android.R.anim.fade_out);
        aniOut.setDuration(3000);

        最后ImageSwitcher imageSwitcher =(ImageSwitcher)findViewById(R.id.imageSwitcher1);
        imageSwitcher.setInAnimation(aniIn);
        imageSwitcher.setOutAnimation(aniOut);
        imageSwitcher.setFactory(本);
        imageSwitcher.setImageResource(图像[指数]);

        最终的处理程序处理程序=新的处理程序();
        可运行可运行=新的Runnable(){

            @覆盖
            公共无效的run(){
                如果(isRunning){
                    指数++;
                    指数=指数%images.length;
                    Log.d(介绍屏幕,更改图片+指数);
                    imageSwitcher.setImageResource(图像[指数]);
                    handler.postDelayed(这一点,间隔);
                }
            }
        };
        handler.postDelayed(可运行,区间);

    }

    @覆盖
    公共查看makeView(){
        ImageView的ImageView的=新ImageView的(这一点);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setLayoutParams(新ImageSwitcher.LayoutParams(
                LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
        返回ImageView的;
    }

    @覆盖
    公共无效结束(){
        isRunning = FALSE;
        super.finish();
    }
}
 

开始下一个活动,在 @覆盖                 公共无效的run(){                     如果(isRunning){

只是检查的指标, 如果该指数等于1,然后开始下一个活动和完成当前;

Okay a little help here, so I have two images loading in my splash screen. The first image opens (starting the splash screen) then the second image opens, once the second image closes the mainactivity starts. Now my question is how do I make my first image fade out, then fade in with my second image?

-Oh yes, and no cross fading -Just a complete fade out and in transition -Thanks in advance

-The splash.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="@+id/lin_lay"
android:gravity="center" >

<ImageView
android:contentDescription="@string/desc"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinning_wheel_image"
android:background="@drawable/splashscreen1" />
</LinearLayout>

The mainanim.xml

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/splashscreen1" android:duration="2500" />
<item android:drawable="@drawable/splashscreen2" android:duration="4000" />
</animation-list>

The Splash.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
    ourSong.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(10500);
            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent openStartingPoint = new Intent("com.theapplication.app.STARTINGPOINT");
                startActivity(openStartingPoint);

            }
        }
    };
    timer.start();
}

@Override
public void setRequestedOrientation(int requestedOrientation) {
    // TODO Auto-generated method stub
    super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
    super.onWindowFocusChanged(hasFocus);
    ImageView mainimage = (ImageView)findViewById(R.id.spinning_wheel_image);
    mainimage.setBackgroundResource(R.anim.mainamin);
    mainanimation = (AnimationDrawable) mainimage.getBackground();
    mainanimation.start();

解决方案

use ImageSwitcher instead of ImageView which support animations by it self. see this sample:

http://www.java2s.com/Code/Android/UI/UsingImageSwitcher.htm

you can add animation like this:

imageSwitcher.setInAnimation(fadeInAnimation);
imageSwitcher.setOutAnimation(fadeOutAnimation);

// my test:

  public class IntroActivity extends Activity implements ViewFactory {

        private static final String TAG = "IntroActivity";

        private final int[] images = { R.drawable.img3, R.drawable.img2,
            R.drawable.img1, R.drawable.img4, R.drawable.img5, R.drawable.img6,
            R.drawable.img7, R.drawable.img8 };
    private int index = 0;
    private final int interval = 10000;
    private boolean isRunning = true;

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_intro);

        startAnimatedBackground();  

    }

    private void startAnimatedBackground() {
        Animation aniIn = AnimationUtils.loadAnimation(this,
                android.R.anim.fade_in);
        aniIn.setDuration(3000);
        Animation aniOut = AnimationUtils.loadAnimation(this,
                android.R.anim.fade_out);
        aniOut.setDuration(3000);

        final ImageSwitcher imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
        imageSwitcher.setInAnimation(aniIn);
        imageSwitcher.setOutAnimation(aniOut);
        imageSwitcher.setFactory(this);
        imageSwitcher.setImageResource(images[index]);

        final Handler handler = new Handler();
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                if (isRunning) {
                    index++;
                    index = index % images.length;
                    Log.d("Intro Screen", "Change Image " + index);
                    imageSwitcher.setImageResource(images[index]);
                    handler.postDelayed(this, interval);
                }
            }
        };
        handler.postDelayed(runnable, interval);

    }

    @Override
    public View makeView() {
        ImageView imageView = new ImageView(this);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setLayoutParams(new ImageSwitcher.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        return imageView;
    }

    @Override
    public void finish() {
        isRunning = false;
        super.finish();
    }
}

to start next activity, in @Override public void run() { if (isRunning) {

just check for the index, if the index equals to 1 then start the next activity and finish the current;