效果是:图片由透明变为不透明,文字由下往上移动
MainActivity.java
package com.example.imagealpha_2;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
private ImageView imageView1,imageView2;
private Animation animation,trans_animation;
private TextView textView2,textView3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView2 = (TextView) findViewById(R.id.textView2);
textView3 = (TextView) findViewById(R.id.textView3);
imageView1 = (ImageView) findViewById(R.id.imageView1);
// imageView2 = (ImageView) findViewById(R.id.imageView2);
animation = AnimationUtils.loadAnimation(MainActivity.this,
R.anim.alpha);
trans_animation = AnimationUtils.loadAnimation(MainActivity.this,
R.anim.transplate);
imageView1.startAnimation(animation);
/// textView2.startAnimation(animation);
textView2.startAnimation(trans_animation);
textView3.startAnimation(trans_animation);
}
}
layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_light"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="99dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="124dp"
android:text="悟空天气" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="生活如虎添翼" />
</RelativeLayout>
alpha.xml
<?xml version="1.0" encoding="UTF-8"?>
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="1500"
android:repeatCount="0"
xmlns:android="http://schemas.android.com/apk/res/android"/>
transpalte.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:fromYDelta="100%p"
android:toYDelta="0%p"
android:repeatMode="restart"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="0"
android:duration="1500" />
</set>