Android 启动页过渡动画效果实现(一)
一.场景1(缩放动画-有小逐渐变大效果)(以下均贴出全部代码(图标、颜色等属性除外),复制即用)
1.效果图:
2.主要函数代码:
import android.animation.FloatEvaluator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import com.hjq.demo.R;
import com.hjq.demo.ui.activity.sgf.banner.RegionTypeDetailsActivity;
import java.util.Calendar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* 仿开眼短视频启动动画
* https://github.com/darryrzhong/OpenEyes
* https://github.com/forvv231/EasyScollImage
*/
public final class OpenEyesActivity extends AppCompatActivity {
@BindView(R.id.iv_bg)
ImageView imageView;
private RecyclerView mRecyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_guide_openeyes);
ButterKnife.bind(this);
initBackground();
startAnimation();//开启动画效果
}
private void initBackground() {
Calendar c = Calendar.getInstance();
int day = c.get(Calendar.DAY_OF_WEEK)-1;
Log.e("!!!!!!!!",day+"");
switch (day){
case 0:
imageView.setBackgroundResource(R.drawable.wallpaper_6);
break;
case 1:
imageView.setBackgroundResource(R.drawable.wallpaper_12);
break;
case 2:
imageView.setBackgroundResource(R.drawable.wallpaper_7);
break;
case 3:
imageView.setBackgroundResource(R.drawable.wallpaper_10);
break;
case 4:
imageView.setBackgroundResource(R.drawable.wallpaper_8);
break;
case 5:
imageView.setBackgroundResource(R.drawable.wallpaper_11);
break;
case 6:
imageView.setBackgroundResource(R.drawable.wallpaper_9);
break;
default:
imageView.setBackgroundResource(R.drawable.wallpaper_9);
}
}
private void startAnimation() {
final View splashIv = findViewById(R.id.iv_bg);
ValueAnimator animator = ValueAnimator.ofObject(new FloatEvaluator(),1.0f,1.2f);
animator.setDuration(3000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
if (value != 1.2f) {
splashIv.setScaleX(value);
splashIv.setScaleY(value);
} else {
goToActivity();
}
}
private void goToActivity() {
Intent intent = new Intent(OpenEyesActivity.this, RegionTypeDetailsActivity.class);
startActivity(intent);
overridePendingTransition(0, android.R.anim.fade_out);
finish();
}
});
animator.start();
}
}
3.布局代码:
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/iv_bg"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:id="@+id/spash_tv_english"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_centerInParent="true"
android:textSize="25sp"
android:text="Eyepetizer" />
android:id="@+id/tv1"
android:text="Daily appetizers for your eyes,Bon eyepetit"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_above="@id/textView"/>
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="每日精选视频推介,让你大开眼界。"
android:layout_marginBottom="46dp"
android:id="@+id/textView"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
4.自定义TextView
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.annotation.Nullable;
/**
* 自定义定制字体的TextView
*/
@SuppressLint("AppCompatCustomView")
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
init(context);
}
public CustomTextView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CustomTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
/*
* 定制字体
* */
private void init(Context context) {
AssetManager assets = context.getAssets();//获取资源文件
Typeface font = Typeface.createFromAsset(assets,"fonts/Lobster-1.4.otf");
setTypeface(font);
}