public class AnimPushCrossFadeHyperSpaceActivity extends Activity implements OnItemSelectedListener{
/** Called when the activity is first created. */
private ViewFlipper mFlipper;
private String [] mStrings = {"PUSH UP", "PUSH LEFT", "CROSS FADE", "HYPERSPACE"};
private TextView mTextViewA;
private TextView mTextViewB;
private TextView mTextView5a;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mFlipper = (ViewFlipper)findViewById(R.id.flipper);
mFlipper.startFlipping();
mTextView5a = (TextView)findViewById(R.id.textview5a);
Spinner s = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mStrings);
s.setAdapter(adapter);
s.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
switch (position){
case 0:
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_out));
break;
case 1:
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
break;
case 2:
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_out));
break;
default:
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.hyperspace_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.hyperspace_out));
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
}
**************************************************
res/layout/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<ViewFlipper
android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:flipInterval="3000" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textviewA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:gravity="center_horizontal"
android:text="Question One"
android:textColor="@color/orange"
android:textSize="26sp" />
<TextView
android:id="@+id/textviewB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="第一題"
android:textColor="@color/yellow"
android:textSize="26sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:gravity="center_horizontal"
android:text="Question Two"
android:textColor="@color/orange"
android:textSize="26sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="第二題"
android:textColor="@color/yellow"
android:textSize="26sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:gravity="center_horizontal"
android:text="Question Three"
android:textColor="@color/orange"
android:textSize="26sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="第三題"
android:textColor="@color/yellow"
android:textSize="26sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:gravity="center_horizontal"
android:text="Question Four"
android:textColor="@color/orange"
android:textSize="26sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="第四題"
android:textColor="@color/yellow"
android:textSize="26sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textview5a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:gravity="center_horizontal"
android:text="Question Five"
android:textColor="@color/orange"
android:textSize="26sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="第五題"
android:textColor="@color/yellow"
android:textSize="26sp" />
</LinearLayout>
</ViewFlipper>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:textColor="@color/lime"
android:text="instructions" />
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
******************************************************
1. res/anim/push_up_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:repeatCount="0">
<translate android:fromYDelta="100%p"
android:toYDelta="0"
android:duration="300"
/>
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300" />
</set>
2. res/anim/push_up_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:repeatCount="0">
<translate android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="300"/>
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="300"/>
</set>
3. res/anim/push_left_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="300"/>
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300"/>
</set>
4. res/anim/push_left_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0"
android:toYDelta="-100%p"
android:duration="300"/>
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="300"/>
</set>
5. res/anim/hyperspace_in.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300"
android:startOffset="1200"
/>
6. res/anim/hyperspace_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<scale
android:duration="700"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.4"
android:toYScale="0.6" />
<set
android:interpolator="@android:anim/accelerate_interpolator"
android:startOffset="700" >
<scale
android:duration="400"
android:fromXScale="1.4"
android:fromYScale="0.6"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.0"
android:toYScale="0.0" />
<rotate
android:duration="400"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-45"
android:toYScale="0.0" />
</set>
</set>
7. res/anim/fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="50">
</alpha>
8. res/anim/fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="50">
</alpha>
沒有留言:
張貼留言