闪屏页(二)
来源:互联网 发布:livin on a prayer知乎 编辑:程序博客网 时间:2024/06/08 14:04
场景
闪屏页(SplashActivity)即应用启动后起始页。
实现
闪屏页定时跳转
主代码
package com.example.administrator.individualresume.view;import android.os.CountDownTimer;import android.view.View;import android.view.WindowManager;import android.widget.LinearLayout;import android.widget.TextView;import com.example.administrator.individualresume.R;import com.example.administrator.individualresume.base.BaseActivity;public class SplashActivity extends BaseActivity implements View.OnClickListener { /*声明控件*/ private TextView tv_time_hint; private LinearLayout linearLayout; // CountDownTimer存一定延迟,有时不可见,故设倒计总长3200 private CountDownTimer countDownTimer = new CountDownTimer(3200, 1000) { @Override public void onTick(long l) { tv_time_hint.setText(l / 1000 + " s"); } @Override public void onFinish() { tv_time_hint.setText(0 + " s"); JumpNoBundleAndFinish(LoginActivity.class); overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left); } }; @Override public void onClick(View view) { switch (view.getId()) { case R.id.linearLayout:// 点击跳转 JumpNoBundleAndFinish(LoginActivity.class); overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left); break; default: break; } } @Override protected void InitView() { // 设全屏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // 加载视图 setContentView(R.layout.activity_splash); // 初始化控件 tv_time_hint = (TextView) findViewById(R.id.tv_time_hint); linearLayout = (LinearLayout) findViewById(R.id.linearLayout); } @Override protected void SetListener() { linearLayout.setOnClickListener(this); } @Override protected void InitVariable() { } @Override protected void InitData() { } @Override protected void CarryOut() { } @Override protected void onResume() { super.onResume(); countDownTimer.start(); } @Override protected void onDestroy() { super.onDestroy(); if (countDownTimer != null) { countDownTimer = null; } }}
布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.administrator.individualresume.view.SplashActivity"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:src="@drawable/splash_page" /> <LinearLayout android:id="@+id/linearLayout" android:layout_width="@dimen/d46" android:layout_height="@dimen/d46" android:layout_alignParentRight="true" android:layout_marginRight="@dimen/d12" android:layout_marginTop="@dimen/d23" android:background="@drawable/title_page_time_hint" android:gravity="center" android:orientation="vertical" android:padding="@dimen/d6"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/jump" android:textColor="@color/colorPrimary" android:textSize="@dimen/s11" /> <TextView android:id="@+id/tv_time_hint" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/colorPrimary" android:textSize="@dimen/s10" tools:text="3s" /> </LinearLayout></RelativeLayout>
drawable
title_page_time_hint
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false"> <stroke android:width="@dimen/d2" android:color="@color/colorPrimary"></stroke> <solid android:color="@color/transparent"></solid></shape>
原理
android.os中类CountDownTimer优点为不需理会线程交互,该类自动处理好。开发者只需在回调中处理时间,设跳转逻辑即可。
注意
不足之处为第一秒倒计时有时不可见,故设倒计总长3200ms。
阅读全文
0 0
- 闪屏页(二)
- (二)
- (二):基二FFT
- 凤凰涅磐(二十-二十五)
- 凤凰涅磐(二十六-二十七)
- 软件中的八二原则(二)
- 二 迭代器(二)相关辅助函数
- 二.Java编程基础(二)
- java提高篇(二二)-----LinkedList
- java提高篇(二二)-----LinkedList
- 黑客编程入门(二。二)
- (二十)java小练习二
- (二十六)svn的问题二
- java提高篇(二二)-----LinkedList
- java提高篇(二二)-----LinkedList
- JAVA二学(二)剖析String
- 二、runtime之类和对象(二)
- 二、tftp实现与说明(二)
- Divide and Conquer -- Leetcode problem240. Search a 2D Matrix II
- IEnumerable和IEnumerator
- Chart.js使用
- Android
- lstm+crf实现命名实体识别
- 闪屏页(二)
- C/C++ 大数加法 动态分配内存
- 浅谈css3的轮播图
- 题目96-n-1位数
- MYSQL数据库四种索引类型的简单使用
- 浏览器的渲染机制
- Mac配置dubbo-admin并启动
- 2018校招顺丰测评
- jn-场馆详情地图标注居中