您的位置:首页 > 移动开发 > Android开发

android 不使用xml的 Animation 简单例子

2012-10-22 16:11 393 查看
关于Animation 使用的时候,网上不断的搜索例子学习

发现都是xml 里面的

对Animation的接受有很多网友说的很清楚了

比如:http://www.moandroid.com/?p=790 他们就得很详细

我也是刚学习的

在这里贴出 不使用xml的 Animation 方法。

testDrawable.java

package test.drawable;

import android.app.Activity;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class testDrawable extends Activity {
	LinearLayout mLinearLayout;

	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);
	    ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);
	    //Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
	    //spaceshipImage.startAnimation(hyperspaceJumpAnimation);
	    
	    Animation animation = null;
	    animation = new TranslateAnimation(0, 300, 0, 500);
	    animation.setFillAfter(true);// True:图片停在动画结束位置
		animation.setDuration(1000);
		spaceshipImage.startAnimation(animation);
		
		
	}
}


main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ImageView  
  android:id="@+id/spaceshipImage" 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:src="@drawable/my_image"/>
</LinearLayout>

下载源码:http://download.csdn.net/detail/penglijiang/4674114
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: