Java代码  
  1. public class Main extends Activity {  
  2.   
  3.     private LayoutInflater m_flater = null;  
  4.     private LinearLayout mFlash;  
  5.   
  6.     public void onCreate(Bundle savedInstanceState) {  
  7.         super.onCreate(savedInstanceState);  
  8.         setContentView(R.layout.flash);  
  9.         mFlash = (LinearLayout) findViewById(R.id.mFlash);  
  10.         mFlash.startAnimation(AnimationUtils  
  11.                 .loadAnimation(this, R.anim.fadeout));  
  12.         m_flater = getLayoutInflater();  
  13.         LoadMainTask task = new LoadMainTask(this);  
  14.         task.execute("");  
  15.   
  16.     }  
  17.   
  18.     public View LoadMainView(LayoutInflater flater) {  
  19.         View view = flater.inflate(R.layout.main, null);  
  20.         Button btnOk = (Button) view.findViewById(R.id.BtnOk);  
  21.         btnOk.setOnClickListener(new OnClickListener() {  
  22.             public void onClick(View v) {  
  23.                 finish();  
  24.             }  
  25.         });  
  26.         return view;  
  27.     }  
  28.   
  29.     private class LoadMainTask extends AsyncTask<Object, Object, View> {  
  30.         public LoadMainTask(Context context) {  
  31.         }  
  32.   
  33.         protected View doInBackground(Object... params) {  
  34.             View view = null;  
  35.             view = LoadMainView(m_flater);  
  36.             // 为了测试加了延时,大家可以在这一块加载资源,数据等  
  37.             try {  
  38.                 Thread.sleep(3000);  
  39.             } catch (InterruptedException e) {  
  40.                 e.printStackTrace();  
  41.             }  
  42.             return view;  
  43.         }  
  44.   
  45.         // 执行完毕  
  46.         protected void onPostExecute(View view) {  
  47.             setContentView(view);  
  48.         }  
  49.     }  
  50.   
  51. }  
posted on 2011-04-15 09:38  kitea  阅读(137)  评论(0)    收藏  举报