我想在短时间内同时更改多个文本视图(> 30)。但是如果这些步骤很短(<100ms),这些变化就会非常滞后。我想归档~10ms。我在nexus 4上调试。这种行为正常吗?这是我的代码:
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]);
}
}
}
}
谢谢!我注意到改变的最后一步比第一步更滞后:S