2013-04-21 60 views
0

我想在短時間內同時更改多個文字瀏覽(> 30)。但如果這些步驟很短(< 100毫秒),則變化非常緩慢。我想實現~10ms。即時通訊調試聯繫4.是行爲正常嗎? 繼承人我的代碼:Android更改多個UI元素

public class AsyncChangeUI extends AsyncTask<Void, Integer, Void> { 
    View view; 
    int oldPercentage; 
    int newPercentage; 

    AsyncChangeUI(View view, int oldPercentage, int newPercentage){ 
     super(); 
     this.view = view; 
     this.oldPercentage = oldPercentage; 
     this.newPercentage = newPercentage; 
    } 

    @Override 
    protected Void doInBackground(Void... params) { 
     Log.e("Kachel", view.getClass().getName()); 

     for(Integer i=this.oldPercentage; i<=newPercentage; i++){ 
      this.oldPercentage = i; 

      try { 
       Thread.sleep(10); //laggy if <100 
       publishProgress(i); 
      }catch(InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 

     return null; 
    } 

    @Override 
    protected void onProgressUpdate(Integer... progress) { 
     List<TileGroupLayout> tileGroupList = ((MainLinearLayout) view).tileGroupList; 

     for (TileGroupLayout tileGroup: tileGroupList) { 
      List<TileLayout> tileList = tileGroup.tileList; 

      for (TileLayout tile: tileList) { 
       tile.changePercentageTo(progress[0]); 
      } 
     }  
    } 
} 

thx! 我注意到改變的最後步驟比第一步更遲緩:S

回答

0

你沒有試過這個沒有調試器連接?調試器真的會減慢你的應用程序。

+0

這應該是評論 – codeMagic 2013-04-21 16:18:29

+0

是的,沒有任何影響。你知道這個影響有多強大嗎? – user2304753 2013-04-21 16:23:52