繁体   English   中英

Android逐渐消失后重定向到新页面

[英]Redirect into New Page after Background Fades Android

我希望我的应用首先使用褪色的图片,然后再使用线程进入另一个页面。 下面是我使用的代码,它对我来说很好用。 但是,它在线程末尾的白页中停止。 我将如何做,以便不单击任何内容即可进入下一个活动? 或者在页面变成白色后,我应该使用什么代码,以便现在转到下一个活动?

package com.kfc;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.*;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class Intro extends Activity {
    LinearLayout screen;
    Handler handler = new Handler();
    int i;
    Intent intent;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.introxml);

        screen = (LinearLayout) findViewById(R.id.myintro);

        (new Thread(){
            @Override
            public void run(){
                for(i=0; i<255; i++){
                    handler.post(new Runnable(){
                        public void run(){
                            screen.setBackgroundColor(Color.argb(255, i, i, i));
                        }
                    });
                    // next will pause the thread for some time
                    try{ sleep(10); }
                    catch(Exception e){ break; }
                }
                for(i=255; i>0; i--){
                    handler.post(new Runnable(){
                        public void run(){
                            screen.setBackgroundColor(Color.argb(255, i, i, i));
                        }
                    });
                    // next will pause the thread for some time
                    try{ sleep(10); }
                    catch(Exception e){ break; }
                }
                startActivity(new Intent(Intro.this,NewKFCActivity.class));
            }
        }).start();
    }
}

for循环退出后。 添加代码以开始新的活动。

startActivity(new Intent(Intro.this,NewACtivity.class));

您需要将其放在for循环之外。 如果将其放在start方法之后,它将在线程完成之前执行。 您可能还需要使用Intro.this来确定“ this变量”的范围。 还记得将新活动添加到清单文件中为

<activity android:name=".NewActivity"/>

只是用这个

screen = (FrameLayout) findViewById(R.id.layout);
(new Thread(){
    @Override
public void run(){
    for(i=0; i<255; i++){
        handler.post(new Runnable(){
            public void run(){
                screen.setBackgroundColor(Color.argb(255, i, i, i));
            }
        });
        // next will pause the thread for some time
        try{ sleep(100); }
           catch(Exception e){ break; }
        }
        startActivity(new Intent(TabTester.this,NewKFCActivity.class));
    }
}).start();

该指针应指向Intro活动对象。 但是在线程内部,这将引用当前线程对象(不确定其确切指向的对象),因此您需要使用“ Intro.this”来对其进行范围划分,这意味着“使用此指向Intro活动”

当将setBackgroundColor用于同一视图时,背景图片将被覆盖。 一种方法是使用布局,外部布局将具有背景图片,内部布局将是已应用setBackgroundColor的布局。 例如:

您还需要更改代码

screen.setBackgroundColor(Color.argb(255, i, i, i));

screen.setBackgroundColor(Color.argb(120, i, i, i));

Alpha值设置为255,表示不透明,不会显示背景图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM