Android啟動(dòng)頁(yè)面定時(shí)跳轉(zhuǎn)的三種方法
從我所做的項(xiàng)目來(lái)看,幾乎都少不了開(kāi)始頁(yè)面,啟動(dòng)頁(yè)面的作用能夠打廣告、發(fā)公告、做緩存處理、更新數(shù)據(jù)等等!Android實(shí)現(xiàn)開(kāi)始頁(yè)面的跳轉(zhuǎn),就是打開(kāi)一個(gè)Android手機(jī)APP的歡迎界面后跳轉(zhuǎn)到指定界面,下面就讓我簡(jiǎn)單介紹下比較常用的開(kāi)始頁(yè)面的跳轉(zhuǎn)方法吧。
一、在onCreate里設(shè)置個(gè)Timer,然后建立Intent指向你要調(diào)用的Activity。設(shè)置Timer 任意秒后執(zhí)行startActivity即可!(Timer是一種定時(shí)器工具,用來(lái)在一個(gè)后臺(tái)線程計(jì)劃執(zhí)行指定任務(wù),它可以計(jì)劃執(zhí)行一個(gè)任務(wù)一次或反復(fù)多次)
final Intent it = new Intent(this, Activity1.class); //你要轉(zhuǎn)向的Activity
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
startActivity(it); //執(zhí)行
}
};
timer.schedule(task, 1000 * 10); //10秒后
二、利用子線程在run方法中設(shè)置跳轉(zhuǎn),用Handler來(lái)執(zhí)行。
public class WelcomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
<span style="white-space:pre"> </span>// TODO Auto-generated method stub
<span style="white-space:pre"> </span>super.onCreate(savedInstanceState);
<span style="white-space:pre"> </span>setContentView(R.layout.welcome);
<span style="white-space:pre"> </span>new Handler().postDelayed(r, 1000);// 1秒后關(guān)閉,并跳轉(zhuǎn)到主頁(yè)面
}
Runnable r = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(WelcomeActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
};
}
三、以動(dòng)畫(huà)形式(旋轉(zhuǎn)、縮放等)作為開(kāi)始頁(yè)面,這種方法在項(xiàng)目中也是比較常用的,比第一種方法多了動(dòng)畫(huà)集,具體看代碼注釋?zhuān)?/p>
開(kāi)始動(dòng)畫(huà)頁(yè)面布局splashMain.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/iv_splash_mainview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash_bg"
android:src="@drawable/splash_sheep_n" />
</LinearLayout>
開(kāi)始動(dòng)畫(huà)頁(yè)面splashActivity.java
public class <span style="font-family: Arial, Helvetica, sans-serif;">splash</span><span style="font-family: Arial, Helvetica, sans-serif;">Activity extends Activity {</span>
private ImageView iv_mainview;
private AnimationSet as;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//去掉標(biāo)題
//requestWindowFeature(Window.FEATURE_NO_TITLE);
initView();// 初始化界面
startAnimation();//開(kāi)始播放動(dòng)畫(huà)
initEvent();//初始化事件
}
private void initEvent() {
//1、監(jiān)聽(tīng)動(dòng)畫(huà)播放完的事件,只是一處用到事件就用匿名類(lèi)對(duì)象,多處聲明成員變量用
as.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
//監(jiān)聽(tīng)動(dòng)畫(huà)播放完
@Override
public void onAnimationEnd(Animation animation) {
//
Intent main = new Intent(<span style="font-family: Arial, Helvetica, sans-serif;">splash</span><span style="font-family: Arial, Helvetica, sans-serif;">Activity </span><span style="font-family: Arial, Helvetica, sans-serif;">.this,MainActivity.class);</span>
startActivity(main);//主界面
//關(guān)閉自己
finish();
}
});
}
/**
* 開(kāi)始播放動(dòng)畫(huà):旋轉(zhuǎn),縮放,漸變
*/
private void startAnimation() {
// false 代表動(dòng)畫(huà)集中每種動(dòng)畫(huà)都采用各自的動(dòng)畫(huà)插入器(數(shù)字函數(shù))
as = new AnimationSet(false);
//旋轉(zhuǎn)動(dòng)畫(huà),錨點(diǎn)
RotateAnimation ra = new RotateAnimation(
0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF,0.5f);//設(shè)置錨點(diǎn)為圖片的中心點(diǎn)
// 設(shè)置動(dòng)畫(huà)播放時(shí)間
ra.setDuration(2000);
ra.setFillAfter(true);//動(dòng)畫(huà)播放完之后,停留在當(dāng)前狀態(tài)
// 添加到動(dòng)畫(huà)集
as.addAnimation(ra);
// 漸變動(dòng)畫(huà)
AlphaAnimation aa = new AlphaAnimation(0, 1);//由完全透明到不透明
//
aa.setDuration(2000);
aa.setFillAfter(true);//
//
as.addAnimation(aa);
// 縮放動(dòng)畫(huà)
ScaleAnimation sa = new ScaleAnimation(
0, 1, 0, 1,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
//
sa.setDuration(2000);
sa.setFillAfter(true);//
//
as.addAnimation(sa);
// 播放動(dòng)畫(huà)
iv_mainview.startAnimation(as);
// 動(dòng)畫(huà)播完進(jìn)入下一個(gè)界面 :向?qū)Ы缑婊蛘咧鹘缑?
//1、監(jiān)聽(tīng)動(dòng)畫(huà)播放完的事件
}
private void initView() {
// 設(shè)置主界面
setContentView(R.layout.onemain);
// 獲取背景圖片
iv_mainview = (ImageView) findViewById(R.id.iv_splash_mainview);
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android?studio?利用共享存儲(chǔ)進(jìn)行用戶的注冊(cè)和登錄驗(yàn)證功能
- Android Studio實(shí)現(xiàn)QQ的注冊(cè)登錄和好友列表跳轉(zhuǎn)
- Android Studio+Servlet+MySql實(shí)現(xiàn)登錄注冊(cè)
- Android Studio連接MySql實(shí)現(xiàn)登錄注冊(cè)(附源代碼)
- Android Studio連接SQLite數(shù)據(jù)庫(kù)的登錄注冊(cè)實(shí)現(xiàn)
- Android使用Intent顯示實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)
- Android Intent實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的兩種方法
- Android 接收推送消息跳轉(zhuǎn)到指定頁(yè)面的方法
- Android實(shí)現(xiàn)外部喚起應(yīng)用跳轉(zhuǎn)指定頁(yè)面的方法
- Android Studio實(shí)現(xiàn)注冊(cè)頁(yè)面跳轉(zhuǎn)登錄頁(yè)面的創(chuàng)建
相關(guān)文章
Android基于OpenCV實(shí)現(xiàn)非真實(shí)渲染
非真實(shí)感渲染(Non Photorealistic Rendering,簡(jiǎn)稱(chēng)NPR),是指利用計(jì)算機(jī)模擬各種視覺(jué)藝術(shù)的繪制風(fēng)格,也用于發(fā)展新的繪制風(fēng)格。比如模擬中國(guó)畫(huà)、水彩、素描、油畫(huà)、版畫(huà)等藝術(shù)風(fēng)格。本文將講解Android基于OpenCV實(shí)現(xiàn)非真實(shí)渲染的方法2021-06-06
雙緩沖技術(shù)實(shí)現(xiàn)Android 畫(huà)板應(yīng)用
這篇文章主要介紹了Android 采用雙緩存技術(shù)實(shí)現(xiàn)畫(huà)板應(yīng)用的相關(guān)資料,并附有代碼實(shí)例,有需要的小伙伴可以參考下2016-07-07
Android自定義View實(shí)現(xiàn)五子棋游戲
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)五子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11
Android 仿高德地圖可拉伸的BottomSheet的示例代碼
這篇文章主要介紹了Android 仿高德地圖可拉伸的BottomSheet的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
android 網(wǎng)絡(luò)請(qǐng)求庫(kù)volley方法詳解
這篇文章主要介紹了android 網(wǎng)絡(luò)請(qǐng)求庫(kù)volley方法詳解的相關(guān)資料,需要的朋友可以參考下2016-09-09
SafeList?in?Flutter?and?Dart小技巧
這篇文章主要為大家介紹了SafeList?in?Flutter?and?Dart小技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
Android之日期及時(shí)間選擇對(duì)話框用法實(shí)例分析
這篇文章主要介紹了Android之日期及時(shí)間選擇對(duì)話框用法,以實(shí)例形式較為詳細(xì)的分析了Android創(chuàng)建日期及時(shí)間選擇對(duì)話框的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09
Android ViewPager實(shí)現(xiàn)左右滑動(dòng)的實(shí)例
這篇文章主要介紹了Android ViewPager實(shí)現(xiàn)左右滑動(dòng)的實(shí)例的相關(guān)資料,這里提供實(shí)現(xiàn)代碼實(shí)現(xiàn)左右滑動(dòng)的功能,希望能幫助到大家,需要的朋友可以參考下2017-08-08

