亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Android SplashScreen 在 ImageView 中更改圖像

Android SplashScreen 在 ImageView 中更改圖像

手掌心 2021-11-11 16:36:11
我是安卓初學者。我每 2 秒就在 ImageView 中制作了一個 SplashScreen 更改 img 圖片。最后一個圖像連續顯示兩次,以避免在移動到 MainActivity 之前立即消失。所以它以某種方式工作 - 圖片正在改變,最后它把用戶帶到 MainActivity 那里我只有一個什么都不做的按鈕(只是為了測試在那里可見)。理論上一切都很好,但每 8 秒 MainActivity 可能會再次重新加載。我可以看到因為 Button 上下跳動 1px。你能看看我的代碼并回答為什么嗎?謝謝你!public class SplashScreen extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    this.requestWindowFeature(Window.FEATURE_NO_TITLE);    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    setContentView(R.layout.activity_splash_screen);    handler.postDelayed(runnable, 0);}@Overrideprotected void onDestroy() {    super.onDestroy();}int[] imageArraySplashScreen = { R.drawable.pierwszy, R.drawable.drugi, R.drawable.trzeci, R.drawable.trzeci};Handler handler = new Handler();Runnable runnable = new Runnable(){    int i = 0;    ImageView splashImageView;    public void run() {        splashImageView = findViewById(R.id.idSplashScreenImageView);        splashImageView.setImageResource(imageArraySplashScreen[i]);        i++;        if (i>imageArraySplashScreen.length-1){            i=0;            Intent splashScreenIntent = new Intent(SplashScreen.this, MainActivity.class );            startActivity(splashScreenIntent);            finish();        }        handler.postDelayed(this, 2000);    }};}
查看完整描述

2 回答

?
烙印99

TA貢獻1829條經驗 獲得超13個贊

嘗試

handler.removeCallbacks(runnable);

在 onPause()


查看完整回答
反對 回復 2021-11-11
?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

僅當圖像要顯示時才需要發布處理程序。只需更改您的代碼,例如,


Handler handler = new Handler();    

Runnable runnable = new Runnable() {

        int i = 0;

        ImageView splashImageView;


        public void run() {


            splashImageView.setImageResource(imageArraySplashScreen[i]);

            i++;

            if (i > imageArraySplashScreen.length - 1) {

                i = 0;

                Intent splashScreenIntent = new Intent(SplashScreen.this, MainActivity.class);

                startActivity(splashScreenIntent);

                finish();

            } else {

                handler.postDelayed(this, 2000);

            }


        }

    };


查看完整回答
反對 回復 2021-11-11
  • 2 回答
  • 0 關注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號