2014-09-12 87 views
0

我numerated像N个位图(使用模拟器)我的SD卡: “1.JPG”, “2.JPG”, “3.JPG”,...ImageView的不刷新

我想将它们加载到我的ImageView中,从“1.jpg”到“xy.jpg”,就像一个短片一样。

但是,经过短暂的延迟后,它只显示保存在我的目录中的最后位图!

基本上,当我点击我的ImageView的 “回放” 按钮:

public void replay(View view) { 
    new replayAsync().execute(); 
} 

这会的AsyncTask执行:

class replayAsync extends AsyncTask<Void, Void, Void> { 

    File temp = null; // This will be the path of the last directory created 

    @Override 
    protected Void doInBackground(Void... params) { 
     int i; 

     // Searching for the last created directory for my replay, 
     // starting from Directory number 10 (newer, if it exists) 
     // to 0 (older) 

     for (i = 10; i > 0; i--) 
     { 
      temp = new File(Environment.getExternalStorageDirectory() 
        + "/Android/data/" 
        + getApplicationContext().getPackageName() 
        + "/Files/" 
        + i); 
      if (!temp.exists()) 
      { 
       continue; 
      } 
      else { 
       System.out.println("last path created is: " + temp); 
       break; 
      } 
     } 


     runOnUiThread(new Runnable(){ 

      @Override 
      public void run() { 

       for (int c = 0; c < 10; c++) { 
        String path = temp + File.separator + c + ".jpg"; 
        Bitmap myBitmap = null; 
        try { 
         myBitmap = BitmapFactory.decodeFile(path); 
         imgView.setImageBitmap(myBitmap); 
         imgView.invalidate(); 
        } 
        catch (Exception e){ 
         System.out.println("Error!"); 
        } 
       } 
      } 
     }); 
     return null; 
    } 
} 

所以,我已经试过无效,postinvalidate,无runOnUiThread,没有AsyncTask,但没有...

它可能是什么?

+0

绘制是在ui线程上完成的,这意味着只有在ui线程上运行的方法完成后才能完成绘制。这意味着直到最后一个图像设置完成才能完成绘图。考虑使用动画对象。 – njzk2 2014-09-12 13:15:40

+0

不应该这个''/ Files /“+我'''/文件/”+我+“.jpg”' – 2014-09-12 13:58:35

回答

0

由于您正在使用for循环从一个图像移动到另一个图像,即使图像发生变化,您也无法看到变化,因为它发生得太快。这个想法将是等待一段时间,然后再转移到下一张图片。您可以使用定时器类在下一个图像显示之前提供一些延迟。

+0

忘记提及:是的,我尝试了Thread.sleep(1000) – Notash 2014-09-12 13:22:35