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(); } }