Android应用的缓冲界面启动界面_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > Android应用的缓冲界面启动界面

Android应用的缓冲界面启动界面

 2013/9/19 23:08:48  jiangmingz  博客园  我要评论(0)
  • 摘要:Java是这么优美的语言,为什么要是用xml做开发,我不喜欢用xml开发。我现在试试所有的例子都不使用xml开发项目。第一个例子启动画面。packagecom.devdiv.test.ui_test_animation;importandroid.app.Activity;importandroid.os.Bundle;importandroid.os.Handler;importandroid.os.Message;importandroid.util.DisplayMetrics
  • 标签:android 应用 启动

Java是这么优美的语言,为什么要是用xml做开发,我不喜欢用xml开发。我现在试试所有的例子都不使用xml开发项目。

第一个例子启动画面。

package com.devdiv.test.ui_test_animation;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

public class UI_Test_AnimationActivity extends Activity {

    private Animation mAnimation;
    private int marginTop;
    private List<ImageView> mImageViews;
    private int[] imageIds = {R.drawable.l, R.drawable.a, R.drawable.o, R.drawable.d,
            R.drawable.i, R.drawable.n, R.drawable.g};

    /**
     * Called when the activity is first created.
     */
    @Override
    public 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();
        marginTop = dm.heightPixels - 100;
        mAnimation = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f, 0.5f, 0.5f);
        mAnimation.setStartOffset(-50);
        mAnimation.setDuration(100);

        LinearLayout mLinearLayout = new LinearLayout(this);
        mLinearLayout.setBackgroundResource(R.drawable.background);

        mImageViews = new ArrayList<ImageView>();

        imageInit(mLinearLayout);

        setContentView(mLinearLayout);

        startAnimation();
    }


    private void imageInit(LinearLayout layout) {

        layout.setGravity(Gravity.CENTER_HORIZONTAL);

        LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(40, 40);
        mParams.setMargins(0, marginTop, 0, 0);

        for (int i : imageIds) {
            ImageView imageView = new ImageView(this);
            imageView.setLayoutParams(mParams);
            layout.addView(imageView);
            mImageViews.add(imageView);
        }
    }


    private void imageClear() {
        for (ImageView image : mImageViews) {
            image.setImageDrawable(null);
            image.destroyDrawingCache();
        }
    }

    Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            int what = msg.what;
            if (what < 7) {
                mImageViews.get(what).setImageDrawable(getResources().getDrawable(imageIds[what]));
                mImageViews.get(what).setAnimation(mAnimation);
            } else {
                imageClear();
            }
        }
    };

    public void startAnimation() {
        new Thread() {

            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                int runCount = 0;

                while (true) {
                    if (runCount < 2) {
                        for (int i = 0; i < 7; i++) {
                            mHandler.sendEmptyMessage(i);

                            try {
                                Thread.sleep(400);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }

                        }
                        runCount++;
                    } else {
                        mHandler.sendEmptyMessage(100);
                        runCount = 0;
                    }
                }
            }

        }.start();
    }
}

 

  

发表评论
用户名: 匿名