本Demo表示一个开场动画,当点下Button,开始动画
1.布局文件,里面有2个图片,要用PS修好
res/layout/Activity_mian
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/imageView_blur"
android:src="@drawable/pic_blur"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:src="@drawable/pic"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:id="@+id/button"/>
</RelativeLayout>
2.Java文件,就是一个简单的OnClickListener
package com.example.blurtest;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
private ImageView mBlurImage;
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBlurImage = (ImageView) findViewById(R.id.imageView);
final Button mButton = (Button)findViewById(R.id.button);
final Animation animation = AnimationUtils.loadAnimation(this,R.anim.alphaanim);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mBlurImage.startAnimation(animation);
}
});
}
}
3.res/anim/alphaanim.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:repeatCount="0"
android:duration="2000"
android:fillAfter="true">
</alpha>