Android turns on the fading effect of animation
- 2021-09-12 02:24:23
- OfStack
When we start a program, we can often see different "boot animation", and the ever-changing animation is only the evolution and beautification of four basic animations.
4 android animation effects:
alpha Gradient Transparency Animation Effect scale gradient size scaling animation effect translate screen conversion position movement animation effect rotate screen transfer rotation animation effectThe simplest one is the gradient transparency effect. This one alone can complete the animation effect of fading and fading (the whole welcome page can be used for fading and fading or the first part of the welcome page):
1) Create a new anim folder in res to hold the action files defined by animation:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="2000"/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="3000"
android:duration="3000"/>
</set>
fromalpha is the transparency at the beginning, toalpha is the transparency at the end, and duration is the time (in milliseconds).
2) Define the layout file (layout):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="@+id/welcom_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/welcome" />
</LinearLayout>
There is no difference between here and the past, just mark the pictures that will gradually appear and fade with id.
3) Implementation method (Activity):
public class WelcomeActivity extends Activity implements AnimationListener {
private ImageView imageView = null;
private Animation alphaAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
imageView = (ImageView) findViewById(R.id.welcom_logo);
alphaAnimation = AnimationUtils.loadAnimation(this,
R.anim.welcome_alpha);
alphaAnimation.setFillEnabled(true);// Start Fill Keep
alphaAnimation.setFillAfter(true);// Set the end of the animation 1 The frame is reserved in the view Above
imageView.setAnimation(alphaAnimation);
alphaAnimation.setAnimationListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_welcome, menu);
return true;
}
@Override
public void onAnimationEnd(Animation animation) {
// End the welcome page at the end of the animation and jump to the main page
Intent intent=new Intent(this,GroupActivity.class);
startActivity(intent);
this.finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
public boolean onKeyDown(int KeyCode,KeyEvent event){
// Mask on Welcome Page BACK Key
if(KeyCode==KeyEvent.KEYCODE_BACK){
return false;
}
return false;
}
}
As the name implies, the welcome page is just decorative. 1 flashes without the return key.