分享一个登录缓冲界面

现在的大多数程序中都有一个缓冲界面,在网上发现了一个很漂亮的缓冲界面,在这里分享一下。主要还是用的android Anim。

java code:

  1. public class Main extends Activity {
  2.     private Animation anm;
  3.     private int marginsTop;
  4.     public List<ImageViewimages;
  5.     public LinearLayout ll;
  6.     @Override
  7.     public void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.  
  10.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREENWindowManager.LayoutParams.FLAG_FULLSCREEN);
  11.  
  12.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  13.  
  14.         DisplayMetrics dm this.getResources().getDisplayMetrics();
  15.  
  16.         int height dm.heightPixels;
  17.         marginsTop height 100;
  18.         anm AnimationUtils.loadAnimation(thisR.anim.myanim);
  19.         ll new LinearLayout(this);
  20.         ll.setBackgroundResource(R.drawable.background);
  21.  
  22.         images new ArrayList<ImageView>();
  23.         initImage(ll);
  24.         playAnimation();
  25.         setContentView(ll);
  26.     }
  27.     private void playAnimation(){        
  28.             new Thread(){
  29.                 @Override
  30.                 public void run()
  31.                 {
  32.                     try {
  33.                         Thread.sleep(1000);
  34.                     catch (InterruptedException e) {
  35.                         e.printStackTrace();
  36.                     }
  37.                     int runcount=0;
  38.                     while(true)
  39.                     {
  40.                         if(runcount<2)
  41.                         {
  42.                             for(int i=0;i<=6;i++)
  43.                             {
  44.                                 handler.sendEmptyMessage(i);
  45.                                 try {
  46.                                     Thread.sleep(400);
  47.                                 catch (InterruptedException e) {
  48.                                     e.printStackTrace();
  49.                                 }
  50.                             }
  51.                             runcount++;
  52.                         }else
  53.                         {
  54.                             handler.sendEmptyMessage(99);
  55.                             runcount=0;
  56.                         }
  57.                         
  58.  
  59.                     }
  60.  
  61.                 }
  62.  
  63.             }.start();
  64.         }
  65.         
  66.  
  67.     Handler handler=new Handler(){
  68.  
  69.                 @Override
  70.                 public void handleMessage(Message msg) {                  
  71.                     switch(msg.what)
  72.                     {
  73.                     case 0:
  74.                         images.get(0).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.l));
  75.                         images.get(0).startAnimation(anm);
  76.                         
  77.                         break;
  78.                     case 1:
  79.                         images.get(1).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.o));
  80.                         images.get(1).startAnimation(anm);
  81.                         break;
  82.                     case 2:
  83.                         images.get(2).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.a));
  84.                         images.get(2).startAnimation(anm);
  85.                         break;
  86.                     case 3:
  87.                         images.get(3).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.d));
  88.                         images.get(3).startAnimation(anm);
  89.                         break;
  90.                     case 4:
  91.                         images.get(4).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.i));
  92.                         images.get(4).startAnimation(anm);
  93.                         break;
  94.                     case 5:
  95.                         images.get(5).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.n));
  96.                         images.get(5).setAnimation(anm);
  97.                         break;
  98.                     case 6:
  99.                         images.get(6).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.g));
  100.                         images.get(6).setAnimation(anm);
  101.                         break;
  102.                     case 99:
  103.                         clearImage();
  104.                         break;
  105.                     }
  106.                 }
  107.             };
  108.     private void clearImage()
  109.     {
  110.         for(ImageView image:images)
  111.         {
  112.             image.setImageDrawable(null);
  113.             image.destroyDrawingCache();
  114.         }
  115.     }
  116.     private void initImage(LinearLayout layout) {
  117.         
  118.         layout.setGravity(Gravity.CENTER_HORIZONTAL);
  119.         LinearLayout.LayoutParams param new LinearLayout.LayoutParams(4040);
  120.         param.setMargins(30marginsTop00);
  121.         
  122.         LinearLayout.LayoutParams param2 new LinearLayout.LayoutParams(4040);
  123.         param2.setMargins(-5marginsTop00);
  124.  
  125.         ImageView l new ImageView(this);
  126.         l.setLayoutParams(param);
  127.         layout.addView(l);
  128.         images.add(l);
  129.  
  130.         ImageView o new ImageView(this);
  131.         o.setLayoutParams(param2);
  132.         layout.addView(o);
  133.         images.add(o);
  134.         
  135.         
  136.         ImageView a new ImageView(this);
  137.         a.setLayoutParams(param2);
  138.         layout.addView(a);
  139.         images.add(a);
  140.         
  141.         ImageView d new ImageView(this);
  142.         d.setLayoutParams(param2);
  143.         layout.addView(d);
  144.         images.add(d);
  145.         
  146.         ImageView i new ImageView(this);
  147.         i.setLayoutParams(param2);
  148.         layout.addView(i);
  149.         images.add(i);
  150.         
  151.         ImageView n new ImageView(this);
  152.         n.setLayoutParams(param2);
  153.         layout.addView(n);
  154.         images.add(n);
  155.         
  156.         ImageView g new ImageView(this);
  157.         g.setLayoutParams(param2);
  158.         layout.addView(g);
  159.         images.add(g);
  160.     }
  161. }

anim code:

  1. <?xml version=“1.0″ encoding=“utf-8″?>
  2.  
  3. <set xmlns:android=“http://schemas.android.com/apk/res/android”
  4.     android:shareInterpolator=“false”>
  5.     <scale android:interpolator=“@android:anim/accelerate_interpolator”
  6.         android:fromXScale=“0.5″ 
  7.         android:toXScale=“1.2″ 
  8.         android:fromYScale=“0.5″
  9.         android:toYScale=“1.2″ 
  10.         android:pivotX=“50%” 
  11.         android:pivotY=“50%”
  12.         android:fillAfter=“false” 
  13.         android:startOffset=“-50″
  14.         android:duration=“100″
  15. />
  16. </set>

显示效果如下:

分享一个登录缓冲界面_第1张图片

你可能感兴趣的:(分享一个登录缓冲界面)