作者puppyulove (WHY)
看板AndroidDev
標題[問題] 手機可以連續播放圖片
時間Wed Feb 17 15:58:41 2016
請問一下要怎麼連續播放圖片
就是假如生成5張圖片
設置每秒鐘播放一張
我的程式碼~
final Runnable r1 = new Runnable() {
public void run() {
try{
Thread.sleep(1000);
matrix2[0] = writer.encode("1234", BarcodeFormat.QR_CODE,500,500);
mQrcodeImage.setImageBitmap(toBitmap(matrix2[0]));
} catch (InterruptedException e) {
e.printStackTrace();
} catch (WriterException e) {
e.printStackTrace();
}
}
};
Thread t1 = new Thread(r1);
t1.start();
我目前是在外面有一張QR code影像 希望可以過一秒後換成這一張影像
但過完一秒後 程式就會跳出來了 xxx以停止運作 請問問題在哪?
拜託大大們~
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.123.115.137
※ 文章網址: https://webptt.com/m.aspx?n=bbs/AndroidDev/M.1455695923.A.0B0.html
※ 編輯: puppyulove (140.123.115.137), 02/17/2016 16:04:38
1F:推 y3k: Thread.currentThread() ? 02/17 16:07
2F:→ puppyulove: 這個怎麼弄呢~ 剛去看了一下 不太懂Orz 02/17 16:18
3F:→ cooper6334: 重點是你怎麼crash的,去看logcat噴了什麼exception 02/17 16:52
4F:→ cooper6334: 觀落陰猜是在非UI Thread上動到View的關係 02/17 16:53
5F:→ puppyulove: Only the original thread that created a view 02/17 17:26
6F:→ puppyulove: hierarchy can touch its views. 02/17 17:26
7F:→ puppyulove: 去查了一下 所以我要在sleep後面新增另一個Threadr2嗎 02/17 17:27
8F:推 cooper6334: 我自己會用Handler+sendMessageDelay來處理 02/17 17:33
9F:→ cooper6334: 自己new的Thread不能改view,google Android UI Thread 02/17 17:35
10F:→ puppyulove: 恩 我去看看要如何用~ 感謝~ 02/17 17:44
11F:推 x51811danny: Drawable Animation? 02/17 18:48
12F:推 x51811danny: 可以試試看 AnimationDrawable 02/17 18:51
13F:→ x51811danny: Sor 沒看清楚 以為你要用res內的圖 02/17 18:57
14F:→ y3k: 上班不能打中文重回一下 你這應該要用Handler 02/17 20:17
15F:推 cakeboy: 簡單的用mQrcodeImage.postDelayed()應該可以 02/17 23:18
16F:推 andy2151: 你view有要做任何更動要在 Main Thread處理 02/18 15:43
17F:→ andy2151: RunOnUiThread或著Handler去處理吧 02/18 15:44
18F:→ puppyulove: 利用handler.postdelayed終於可以換了~ 02/25 14:39
19F:→ puppyulove: 不過要怎麼換多張呢~ 只能換一張而以 Orz 02/25 14:40