package com.example.theoryproject1;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.*;
public class Viewanimator3 extends Activity
{
private ViewAnimator va1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.viewanimator3);
va1 = (ViewAnimator)findViewById(R.id.viewAnimator1);
Animation inAnim = new AlphaAnimation(0,1);
inAnim.setDuration(2000);
Animation outAnim = new AlphaAnimation(1,0);
outAnim.setDuration(2000);
va1.setInAnimation(inAnim);
va1.setOutAnimation(outAnim);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction()==MotionEvent.ACTION_UP)
{
va1.showNext();
}
return true;
}
}
____________________
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ViewAnimator
android:id="@+id/viewAnimator1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.6" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="程式設計" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美工設計" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="資料庫設計" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手機程式設計" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="網頁設計" />
</ViewAnimator>
</LinearLayout>
</LinearLayout>
沒有留言:
張貼留言