汉诺塔android动画演示程序

汉诺塔android动画演示程序_第1张图片汉诺塔android动画演示程序_第2张图片汉诺塔android动画演示程序_第3张图片

/**
 * 汉诺塔android演示程序。
 * @author tianhongyan
 *
 */
@SuppressLint("NewApi")
public class HannuoActivity extends Activity implements AnimatorListener{

	//初始化汉诺塔塔块的个数(本例以5个演示)
	private int hannuoCount=5;
	//动画演示区域
	private LinearLayout contentView;
	//动画序列target集合,也就是第几步骤所要移动的是哪个塔块的集合
	private List allItemsInAnimation=new ArrayList();
	//动画序列起点和终点的集合,也就是第几步骤塔块从哪个位置移动到哪个位置。
	private List fromAndToList=new ArrayList();
	//记录每一时刻0,1,2这三个位置上各有多少个塔块
	private List positionCountList=new ArrayList();
	//动画序列描述,也就是描述第几步骤哪个塔块从哪个位置移动到哪个位置。
	private List descList=new ArrayList();
	private int screenWidth;
	private int countM=0;
	private Handler myhandler;
	private TextView description;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hannuo_activity_main);
		WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
		screenWidth = windowManager.getDefaultDisplay().getWidth();
		description=(TextView) findViewById(R.id.description);
		initView();
	}
	@SuppressLint("ResourceAsColor")
	private void initView(){
		contentView=(LinearLayout) findViewById(R.id.content);
		//设置动画演示区域的参数
		LinearLayout.LayoutParams layoutp=(LayoutParams) contentView.getLayoutParams();
		layoutp.leftMargin=0;
		layoutp.rightMargin=0;
		layoutp.width=screenWidth;
		layoutp.height=screenWidth;
		contentView.setLayoutParams(layoutp);
		//初始化页面,往动画演示区域添加汉诺塔塔块
		for(int i=0;i=1){
	    	 Integer[] a=positionCountList.get(countM);
		     anim03 = ObjectAnimator.ofFloat(animationTargart, "y",0,contentView.getHeight()-20-a[to]*20).setDuration(2000);
	     }else{
	    	 anim03 = ObjectAnimator.ofFloat(animationTargart, "y",0,contentView.getHeight()-20).setDuration(2000);
	     }
	     AnimatorSet animSet = new AnimatorSet();
	     animSet.playSequentially(anim01,anim02,anim03);    
	     animSet.addListener(this);
	     int step=countM+1;
	     description.setText("["+step+"],"+descList.get(countM));
	     animSet.start();
	}
	public void startAimation(View view){
		hannuo(hannuoCount,0,1,2);
		doAnimation();
	    myhandler=new Handler(){
		    @Override
		    public void handleMessage(android.os.Message msg) {
			    switch (msg.what) {
			    case 1:
				    countM++;
				    if(countM
    
    
    
    
	    


 
 

你可能感兴趣的:(汉诺塔android动画演示程序)