Android UI開發第十五篇——分享一個登入緩衝介面

來源:互聯網
上載者:User

今天在網上發現了一個很漂亮的緩衝介面,在這裡分享一下。主要還是用的android Anim。

java code:

public class Main extends Activity {private Animation anm;private int marginsTop;public List<ImageView> images;public LinearLayout ll;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);requestWindowFeature(Window.FEATURE_NO_TITLE);DisplayMetrics dm = this.getResources().getDisplayMetrics();int height = dm.heightPixels;marginsTop = height - 100;anm = AnimationUtils.loadAnimation(this, R.anim.myanim);ll = new LinearLayout(this);ll.setBackgroundResource(R.drawable.background);images = new ArrayList<ImageView>();initImage(ll);playAnimation();setContentView(ll);}private void playAnimation() {new Thread() {@Overridepublic void run() {try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}int runcount = 0;while (true) {if (runcount < 2) {for (int i = 0; i <= 6; i++) {handler.sendEmptyMessage(i);try {Thread.sleep(400);} catch (InterruptedException e) {e.printStackTrace();}}runcount++;} else {handler.sendEmptyMessage(99);runcount = 0;}}}}.start();}Handler handler = new Handler() {@Overridepublic void handleMessage(Message msg) {switch (msg.what) {case 0:images.get(0).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.l));images.get(0).startAnimation(anm);break;case 1:images.get(1).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.o));images.get(1).startAnimation(anm);break;case 2:images.get(2).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.a));images.get(2).startAnimation(anm);break;case 3:images.get(3).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.d));images.get(3).startAnimation(anm);break;case 4:images.get(4).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.i));images.get(4).startAnimation(anm);break;case 5:images.get(5).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.n));images.get(5).setAnimation(anm);break;case 6:images.get(6).setImageDrawable(Main.this.getResources().getDrawable(R.drawable.g));images.get(6).setAnimation(anm);break;case 99:clearImage();break;}}};private void clearImage() {for (ImageView image : images) {image.setImageDrawable(null);image.destroyDrawingCache();}}private void initImage(LinearLayout layout) {layout.setGravity(Gravity.CENTER_HORIZONTAL);LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(40, 40);param.setMargins(30, marginsTop, 0, 0);LinearLayout.LayoutParams param2 = new LinearLayout.LayoutParams(40, 40);param2.setMargins(-5, marginsTop, 0, 0);ImageView l = new ImageView(this);l.setLayoutParams(param);layout.addView(l);images.add(l);ImageView o = new ImageView(this);o.setLayoutParams(param2);layout.addView(o);images.add(o);ImageView a = new ImageView(this);a.setLayoutParams(param2);layout.addView(a);images.add(a);ImageView d = new ImageView(this);d.setLayoutParams(param2);layout.addView(d);images.add(d);ImageView i = new ImageView(this);i.setLayoutParams(param2);layout.addView(i);images.add(i);ImageView n = new ImageView(this);n.setLayoutParams(param2);layout.addView(n);images.add(n);ImageView g = new ImageView(this);g.setLayoutParams(param2);layout.addView(g);images.add(g);}}

anim code:

<?xml version="1.0" encoding="utf-8"?>    <set xmlns:android="http://schemas.android.com/apk/res/android"      android:shareInterpolator="false">      <scale android:interpolator="@android:anim/accelerate_interpolator"          android:fromXScale="0.5"           android:toXScale="1.2"           android:fromYScale="0.5"          android:toYScale="1.2"           android:pivotX="50%"           android:pivotY="50%"          android:fillAfter="false"           android:startOffset="-50"          android:duration="100"  />  </set>  
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.