Android 启动页面弹出效果

OCRus支持三种语言的识别:英语、中文和日文。这三个Tesseract语言包合起来约有70M左右,APK文件中拷贝语言包到手机存储中需要几秒时间,所以我们做了一个启动页面,在为用户展示App第一印象的同时,后台拷贝这三个语言包。经过比较,知乎日报的启动页面有从中心点展开逼进用户的效果,我们决定利用此效果来设计启动页面。最终效果如图所示:
splashScreen

下面就实现方式进行详细介绍。

layout.xml

首先创建此页面的布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:src="@drawable/splash" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:textSize="24dp"
        android:textColor="@color/bright_foreground_material_dark"
        android:gravity="center_horizontal"
        android:layout_alignParentBottom="true"
        android:text="@string/app_name" />

</RelativeLayout>

此布局中包含一个ImageView和一个TextView。ImageView即显示的图片,TextView是显示最下面的App名字。

Activity

然后创建一个新的Activity,在AndroidManifest.xml中将其设置为启动Activity:

<activity android:name=".SplashActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

并在该Activity的onCreate方法中设置图片动画:

Animation animation = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // 将图片放大1.2倍,从中心开始缩放
animation.setDuration(SPLASH_TIME_OUT); // 动画持续时间
animation.setFillAfter(true); // 动画结束后停留在结束的位置
animation.setAnimationListener(this);
splashImage.startAnimation(animation);

在动画结束时,画面要跳转到MainActivity。为此,SplashActivity需实现Animation.AnimationListener,在onAnimationEnd方法中,跳转到MainActivity:

public void onAnimationEnd(Animation animation) {
    Intent i = new Intent(SplashActivity.this, MainActivity.class);
    startActivity(i);
    finish();
}

实现效果如图所示,具体实例详见Github

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值