美文网首页
启动界面

启动界面

作者: TTTqiu | 来源:发表于2016-09-18 17:41 被阅读29次

1. 方法一:SplashActivity 作为主 Activity,定时跳转到 MainActivity:

package com.ttt.zhihudaily.activity;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import com.ttt.zhihudaily.R;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        // 动画
        ImageView imageView=(ImageView)findViewById(R.id.splash_image);
        TextView textView1=(TextView)findViewById(R.id.splash_text_1);
        TextView textView2=(TextView)findViewById(R.id.splash_text_2);
        AlphaAnimation imageAnimation=new AlphaAnimation(0.0f,1.0f);
        imageAnimation.setDuration(1000);
        imageView.setAnimation(imageAnimation);
        AlphaAnimation textAnimation=new AlphaAnimation(0.0f,1.0f);
        textAnimation.setDuration(300);
        textView1.setAnimation(textAnimation);
        textView2.setAnimation(textAnimation);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent=new Intent(SplashActivity.this,MainActivity.class);
                SplashActivity.this.startActivity(intent);
                SplashActivity.this.finish();
            }
        },2000);
    }
}

2. 方法二:直接在 MainActivity 中,通过设置 Visibility 实现。

<?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=".activity.MainActivity">

    <android.support.v4.widget.DrawerLayout...>

    <LinearLayout
        android:id="@+id/splash_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/white">

        <ImageView
            android:id="@+id/splash_image"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="5"
            android:scaleType="centerCrop"
            android:src="@drawable/splash_image"/>

        <TextView
            android:id="@+id/splash_text_1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:gravity="center"
            android:layout_weight="1"
            android:textSize="40sp"
            android:textColor="@color/colorPrimary"
            android:text="知乎日报"/>

        <TextView
            android:id="@+id/splash_text_2"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center_horizontal"
            android:textSize="15sp"
            android:textColor="@color/colorPrimary"
            android:text="By   TTTqiu"/>

    </LinearLayout>

</RelativeLayout>
    ......
    private void initSplash(){
        // 防止启动界面时 RelativeLayout 下的主界面会响应事件
        drawerLayout.setVisibility(View.INVISIBLE);

        ImageView splashImage=(ImageView)findViewById(R.id.splash_image);
        TextView splashText1=(TextView)findViewById(R.id.splash_text_1);
        TextView splashText2=(TextView)findViewById(R.id.splash_text_2);

        AlphaAnimation imageAnimation=new AlphaAnimation(0.0f,1.0f);
        imageAnimation.setDuration(1000);
        splashImage.setAnimation(imageAnimation);

        AlphaAnimation textAnimation=new AlphaAnimation(0.0f,1.0f);
        textAnimation.setDuration(1000);
        textAnimation.setStartOffset(800);
        splashText1.setAnimation(textAnimation);
        splashText2.setAnimation(textAnimation);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                LinearLayout splashLayout=(LinearLayout)findViewById(R.id.splash_layout);
                AlphaAnimation layoutAnimation=new AlphaAnimation(1.0f,0.0f);
                layoutAnimation.setDuration(500);
                splashLayout.setAnimation(layoutAnimation);
                splashLayout.setVisibility(View.GONE);
                drawerLayout.setVisibility(View.VISIBLE);
            }
        },2500);
    }
    ......

相关文章

  • UI界面设计-APP界面控件中英文名称汇总

    一、界面模式Mobile Design Pattern 1. 启动界面 (智能手机启动时所显示的界面) 启动界面/...

  • CentOS 7 设置默认启动的界面

    1、查看当前系统默认启动的界面 2,设置默认启动界面为图形界面 3,设置默认启动界面为命令行界面

  • CentOS 7 修改默认启动的界面

    1.先查看当前系统默认启动的界面 2.修改默认启动界面为图形界面 3.修改默认启动界面为字符(命令行)界面

  • 无需U盘破解Win7开机密码

    开机时按F8让启动界面进入到这里 再开机时,启动界面会显示如下图 再开机时,启动界面会显示下面的界面 选择启动修复...

  • iOS自定义启动界面

    iOS自定义启动界面 iOS自定义启动界面

  • 启动界面

    1. 方法一:SplashActivity 作为主 Activity,定时跳转到 MainActivity: 2....

  • 移动APP测试用例设计的部分关键点

    1.应用的启动和停止 首次启动 是否出现欢迎界面,欢迎界面的停留时间合理,欢迎界面后是否正常进入应用; 首次启动时...

  • 初步认识PS界面

    打开PS软件,可以看到PS启动的界面是这个样子,每个版本的启动界面还是有所区别的,我的版本是CC2019,启动界面...

  • Launcher界面结构

    Launcher界面结构 Launcher UI 结构 启动器界面结构 前置文章 《Launcher的启动过程 》...

  • 第八章 SharedPreferences

    启动的时候有张引导界面、只有第一次启动时显示,3秒后到主界面。下一次启动就不会再显示引导界面了,直接到主界面。 课...

网友评论

      本文标题:启动界面

      本文链接:https://www.haomeiwen.com/subject/cbcgettx.html