033 Android App启动的闪屏效果+新手向导(多个图片滑动效果)+ViewPager使用
1.目标效果
App启动时,出现闪屏效果(利用动画实现)。
App新手使用时,会出现新手向导效果。
2.XML页面布局
(1)闪屏页面
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rl_main"
android:background="@mipmap/splash_bg_newyear"
tools:context=".MainActivity"> <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/splash_horse_newyear"/> </RelativeLayout>
(2)UserGuideActivity页面布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UserGuideActivity"> <android.support.v4.view.ViewPager
android:id="@+id/vp_user_guide"
android:layout_width="match_parent"
android:layout_height="match_parent"> </android.support.v4.view.ViewPager> <Button
android:id="@+id/bt_userguide_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@drawable/selector_btn_text_user_guide"
android:padding="10dp"
android:background="@drawable/selector_btn_user_guide"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="100dp"
android:text="开始体验"/> <RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="75dp"> <LinearLayout
android:id="@+id/ll_guide_spot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"> </LinearLayout> <ImageView
android:id="@+id/iv_red_spot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/user_spot_red"/>
</RelativeLayout> </RelativeLayout>
(3)图片选择器
<1>按钮的背景图
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/button_red_pressed"></item>
<item android:drawable="@drawable/button_red_normal"></item>
</selector>
<2>按钮上的文字的选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#000" android:state_pressed="true"></item>
<item android:color="#fff"></item>
</selector>
3.java后台代码
(1)MainActivity.class
package com.example.administrator.test66smartbeijing; import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout; import com.example.administrator.test66smartbeijing.utils.ConstantValue;
import com.example.administrator.test66smartbeijing.utils.SharePreferenceUtil; /**
* 闪屏页面(通过动画实现)
*/
public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); RelativeLayout rl_main=findViewById(R.id.rl_main);
//设置旋转动画
RotateAnimation rotateAnimation=new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
rotateAnimation.setDuration(1000); //设置动画时间
rotateAnimation.setFillAfter(true); //保持动画结束状态 //设置缩放动画
ScaleAnimation scaleAnimation=new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
scaleAnimation.setDuration(1000);
scaleAnimation.setFillAfter(true); //渐变动画
AlphaAnimation alphaAnimation=new AlphaAnimation(0,1);
alphaAnimation.setDuration(2000); //设置动画时间
alphaAnimation.setFillAfter(true); //保持动画结束状态 //动画集合
AnimationSet animationSet=new AnimationSet(true);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(alphaAnimation); //启动动画
rl_main.startAnimation(animationSet); //给动画添加监听事件
animationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { } @Override
public void onAnimationEnd(Animation animation) {
//动画结束后执行
//用SharedPreferences存储用户是否是第一次进入的状态
boolean is_first_enter=SharePreferenceUtil.getBoolean(getApplicationContext(),ConstantValue.IS_FIRST_ENTER,true);
Intent intent;
if(is_first_enter){
//进入新手引导界面
intent=new Intent(getApplicationContext(),UserGuideActivity.class);
}else {
//进入主界面
intent=new Intent(getApplicationContext(),MainFunctionActivity.class);
}
startActivity(intent); //开启页面跳转
finish();//结束当前页面
} @Override
public void onAnimationRepeat(Animation animation) { }
});
}
}
(2)
package com.example.administrator.test66smartbeijing; import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout; import java.util.ArrayList;
import java.util.List; public class UserGuideActivity extends AppCompatActivity { ViewPager viewPager;
LinearLayout ll_guide_spot;
ImageView iv_red_spot;
Button bt_userguide_start;
//创建一个数组用来存放新手向导的图片
int[] imageIdArray=new int[]{R.mipmap.guide_1,R.mipmap.guide_2,R.mipmap.guide_3};
List<ImageView> imageViewList; //用来存放ImageView控件的集合
int moveDistance; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_guide); viewPager = findViewById(R.id.vp_user_guide);
ll_guide_spot=findViewById(R.id.ll_guide_spot);
iv_red_spot=findViewById(R.id.iv_red_spot);
bt_userguide_start=findViewById(R.id.bt_userguide_start);
bt_userguide_start.setVisibility(View.INVISIBLE); initData();
viewPager.setAdapter(new MyViewPager()); //给viewpager设置适配器
//给viewpager设置滑动监听事件
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//当页面滑动过程中回调
//更新页面中小红点的位置
//1.计算小红点当前的左边距
int leftMargin= (int) (moveDistance*positionOffset)+position*moveDistance;
//2.获取当前小红点的布局参数
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) iv_red_spot.getLayoutParams();
//3.修改左边距
layoutParams.leftMargin=leftMargin;
//4.重新设置布局参数
iv_red_spot.setLayoutParams(layoutParams);
} @Override
public void onPageSelected(int position) {
//某个页面被选中
if(position==imageIdArray.length-1){
bt_userguide_start.setVisibility(View.VISIBLE);
}else {
bt_userguide_start.setVisibility(View.INVISIBLE);
}
} @Override
public void onPageScrollStateChanged(int state) { }
}); iv_red_spot.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
iv_red_spot.getViewTreeObserver().removeOnGlobalLayoutListener(this); //移除监听,避免重复回调
//计算两个小圆点之间的距离
//小红点的移动距离=第二个小圆点的left值-第一个小圆点的left值
moveDistance=ll_guide_spot.getChildAt(1).getLeft()-ll_guide_spot.getChildAt(0).getLeft();
}
});
} //初始化数据
private void initData() {
imageViewList=new ArrayList<>();
for (int i = 0; i <imageIdArray.length ; i++) {
ImageView imageView=new ImageView(getApplicationContext());
imageView.setBackgroundResource(imageIdArray[i]);
imageViewList.add(imageView); //初始化小圆点
ImageView spot=new ImageView(getApplicationContext());
spot.setImageResource(R.drawable.user_spot_gray);
//初始化布局参数
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
if(i>0){
params.leftMargin=15;
}
spot.setLayoutParams(params); //设置小圆点的间距
ll_guide_spot.addView(spot);
}
} private class MyViewPager extends PagerAdapter {
//返回item的个数
@Override
public int getCount() {
return imageViewList.size();
} @Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view==object;
} //初始化item布局
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
ImageView imageView=imageViewList.get(position);
container.addView(imageView);
return imageView;
} //销毁item
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
}
}
4.效果图

033 Android App启动的闪屏效果+新手向导(多个图片滑动效果)+ViewPager使用的更多相关文章
- android app启动就闪退怎么办?
开发过程中,如遇到android app启动就闪退,不要急,直接进入调试模式运行app,就会取得出错的原因. http://blog.sina.com.cn/s/blog_44fa172f0102wg ...
- Android app启动出现白屏闪屏
出现白屏闪屏原因: 进入到AppStartActivity,但是未加载到布局文件,就先显示了窗口的背景,白屏就是显示的windows的背景,即所设置的theme. onCreate()中的setCon ...
- Android App 启动页(Splash)黑/白闪屏现象产生原因与解决办法(转)
转载: Android App 启动页(Splash)黑/白闪屏现象产生原因与解决办法 首先感谢博主分享,本文作为学习记录 惊鸿一瞥 微信的启动页,相信大家都不陌生. 不知道大家有没有发现一个现象 ...
- [FMX] Android APP 启动黑屏优化补丁
使用说明 *************************************************** Android APP 启动黑屏优化补丁 作者: Swish, YangYxd 201 ...
- Android 解决启动页白屏或者黑屏的问题
欢迎页启动的线程由于请求和处理的数据量过大而,导致欢迎页在出现之前界面上会有一个短暂的白色闪屏停留,当然白色闪屏的停留是因为 application 的主题样式android:theme=@style ...
- Android Activity启动黑/白屏原因与解决方式
Android Activity启动黑/白屏原因与解决方式 我们新建一个HelloWorld项目,运行在手机上时,Activity打开之前会有一个动画,而这个动画里是全白或者全黑的(取决于你的主题是亮 ...
- Android app启动activity并调用onCreate()方法时都默默地干了什么?
Android app启动activity并调用onCreate() 方法时都默默地干了什么? 在AndroidManifest.xml文件中的<intent-filter>元素中有这 ...
- Android app启动是出现白屏或者黑屏如何解决?
1.为什么 APP 启动时会出现白屏或者黑屏? 当打开一个 Activity 时,如果这个 Activity 所属的应用还没有在运行,系统会为这个 Activity 所属的应用创建一个进程,但进程的创 ...
- android开发之splash闪屏页判断是否第一次进入app代码
package com.david.david.zhankudemo.activity; import android.app.Activity; import android.content.Con ...
随机推荐
- Linux压缩和解压类指令
一.gzip / gunzip 指令 gzip 用于压缩文件,gunzip 用于解压文件. 基本语法gizp 文件 (功能描述:只能将文件压缩为*.gz文件)gunzip 文件.gz (功能描述 ...
- Linux下CRMEB环境搭建
环境准备:PHP7.0.33MySQL5.7Apache2.4 PHP环境安装: sudo apt--cli php7.-common php7.-curl \ php7.-dev php7.-fpm ...
- BAT 电脑名 用户名
@echo offecho 当前盘符:%~d0echo 当前登陆用户:%username%echo 当前盘符和路径:%~dp0echo 当前盘符和路径的短文件名格式:%~sdp0echo 当前批处理全 ...
- spring线程池的同步和异步(1)
spring线程池(同步.异步) 一.spring异步线程池类图 二.简单介绍 2.1. TaskExecutor---Spring异步线程池的接口类,其实质是java.util.concurrent ...
- JVM 类加载器的双亲委托机制
1.类加载器的层次结构 在双亲委托机制中,各个加载器按照父子关系形成了树形结构(逻辑意义),除了根加载器之外,其余的类加载器都有且只有一个父加载器. public class MyTest13 { p ...
- 【转】自动化框架中引入ExtentReport美化报告
本文链接:https://blog.csdn.net/qq_30353203/article/details/82023922一.先引入三个依赖包 <dependency> <gro ...
- https://zhuanlan.zhihu.com/p/32553477
科普:QUIC协议原理分析
- js中const,var,let区别与用法(转)
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/qq_36784628/article/d ...
- 20161209pod search 'fmdb'提示[!] Unable to find a pod with name, author, summary, or description matching `fmdb`
从SVN上更新工程之后运行工程提示错误: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update y ...
- linux内核的0号进程是在哪里创建的?
1. 0号进程即为idle进程或swapper进程,也就是空闲进程 2. 0号进程特点 idle是一个进程,其pid为0. 主处理器上的idle由原始进程(pid=0)演变而来.从处理器上的idle由 ...