android 启动活动 动画,Android 启动页过渡动画效果实现(一)

本文详细介绍了如何在Android中实现启动页的过渡动画,包括缩放、旋转和位移效果。通过示例代码展示了如何创建并启动这些动画,同时也提供了不同场景的动画实现,帮助开发者打造更加流畅和吸引人的启动体验。文章还提到了一些处理启动黑屏或白屏问题的方法。
摘要由CSDN通过智能技术生成

Android 启动页过渡动画效果实现(一)

一.场景1(缩放动画-有小逐渐变大效果)(以下均贴出全部代码(图标、颜色等属性除外),复制即用)

1.效果图:

lj710QzxO-CRwjh8XbIXqzicINtF

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);

}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值