Android AnimationDrawable.setBackgroundResource需要很多时间

Android AnimationDrawable.setBackgroundResource需要很多时间,android,Android,我的应用程序中有一个问题,setBackgroundResource需要大量的处理时间。是否有任何方法可以在另一个线程中运行此方法,我尝试使用AsyncTask,但它无法访问UI线程。在处理此方法时,是否有任何方法可以执行其他任务? Thx提前 您可以在AsyncTask中加载drawable,然后从complete中修改UI: new AsyncTask<Void, Void, Drawable>() { protected Drawable doInBackground(

我的应用程序中有一个问题,setBackgroundResource需要大量的处理时间。是否有任何方法可以在另一个线程中运行此方法,我尝试使用AsyncTask,但它无法访问UI线程。在处理此方法时,是否有任何方法可以执行其他任务?

Thx提前

您可以在AsyncTask中加载drawable,然后从complete中修改UI:

new AsyncTask<Void, Void, Drawable>() {
    protected Drawable doInBackground(Void... ignored) { 
        return context.getResources().getDrawable(R.drawable.giant); 
    }
    protected void onPostExecute(Drawable d) { 
        myView.setBackgroundDrawable(d);
    }
}
newasynctask(){
受保护的可绘制doInBackground(无效…忽略){
返回context.getResources().getDrawable(R.drawable.giant);
}
受保护的void onPostExecute(可提取的d){
我的观点。退步可拉深(d);
}
}

“setBackgroundResource需要大量的处理时间”--您是如何确定这一点的(例如,通过Traceview)?你用了这么长时间的背景资源做什么?我打赌他在AnimationDrawableYesk中使用了数百个png。我有很多png图像,有没有办法在其他线程中执行此任务