Android啟動動畫實現
首先提一下實現機制:
1.將manifest中launcher頁設為我們需要顯示的啟動頁面。
2.在啟動動畫頁面中我們先載入我們需要的啟動頁面(動畫、文字、廣告等)。
3.在啟動頁的activity中利用執行緒的postDelayed方法來延遲3s,3s後便執行跳轉到主介面或者
登入介面(也可以通過檢查SharedPreferences中是否記住了使用者歷史賬號資訊,有記住就直接
執行登入操作,沒有就跳轉到登入頁面)。
PS:解決啟動頁面白屏:傳送實現步驟:
一、新建啟動頁StartActivity
package cn.com.box.black.bbnotepad.Activity; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.annotation.RequiresApi; import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewCompat; import android.support.v7.app.AppCompatActivity; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.CheckBox; import android.widget.FrameLayout; import android.widget.Toast; import com.airbnb.lottie.LottieAnimationView; import cn.com.box.black.bbnotepad.Bean.SuccessBean; import cn.com.box.black.bbnotepad.Listener.TListener; import cn.com.box.black.bbnotepad.Model.LoginModel; import cn.com.box.black.bbnotepad.R; import static cn.com.box.black.bbnotepad.Server.AUTO_LOGIN; import static cn.com.box.black.bbnotepad.Server.user_id_remember; import static com.githang.statusbar.StatusBarTools.getStatusBarHeight; /** * Created by gcj on 2017/11/28 */ public class StartActivity extends AppCompatActivity { private Handler handler = new Handler(); private LottieAnimationView mAnimationView; private String username,userpass; private CheckBox checkBox; private String userid; private boolean check; TListener<SuccessBean> tListener = new TListener<SuccessBean>() { @Override public void onResponse(SuccessBean loginBean) { userid = loginBean.getSuccess().toString(); //記錄使用者id // showToast(userid); user_id_remember= Integer.parseInt(userid); if(loginBean.getSuccess().toString().equals("0")){ Toast.makeText(StartActivity.this,"登陸失敗",Toast.LENGTH_SHORT).show(); Intent intent = new Intent(StartActivity.this, LoginActivity.class); startActivity(intent); finish(); } else{ // Toast.makeText(LoginActivity.this,"登陸成功",Toast.LENGTH_SHORT).show(); Intent intent = new Intent(); intent.setClass(StartActivity.this, MainActivity1.class); startActivity(intent); finish(); } } @Override public void onFail(String msg) { Toast.makeText(StartActivity.this,"登陸失敗",Toast.LENGTH_SHORT).show(); Intent intent = new Intent(StartActivity.this, LoginActivity.class); startActivity(intent); finish(); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // getSupportActionBar().hide(); if (Build.VERSION.SDK_INT <= 19) { setStatusBarColor4_4(this, ContextCompat.getColor(this, R.color.back_red) ); } else { setStatusBarColor(this,ContextCompat.getColor(this, R.color.back_red) ); } // 注意:此處將setContentView()方法註釋掉 setContentView(R.layout.activity_start); check=getUser_remember(); handler.postDelayed(new Runnable() { @Override public void run() { gotoLogin(); } }, 3000); } /** * 前往註冊、登入主頁 */ private void gotoLogin() { username = getUser_name(); userpass = getUser_password(); if(AUTO_LOGIN==0) { LoginModel loginModul = new LoginModel(); loginModul.getUserList(username, userpass, tListener); }else{ Intent intent = new Intent(StartActivity.this, LoginActivity.class); startActivity(intent); finish(); } //取消介面跳轉時的動畫,使啟動頁的logo圖片與註冊、登入主頁的logo圖片完美銜接 overridePendingTransition(0, 0); } /** * 遮蔽物理返回鍵 */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { return true; } return super.onKeyDown(keyCode, event); } @Override protected void onDestroy() { if (handler != null) { //If token is null, all callbacks and messages will be removed. handler.removeCallbacksAndMessages(null); } super.onDestroy(); } @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) static void setStatusBarColor(Activity activity, int statusColor) { Window window = activity.getWindow(); //取消狀態列透明 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //新增Flag把狀態列設為可繪製模式 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //設定狀態列顏色 window.setStatusBarColor(statusColor); //設定系統狀態列處於可見狀態 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); //讓view不根據系統視窗來調整自己的佈局 ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } } static void setStatusBarColor4_4(Activity activity, int statusColor) { Window window = activity.getWindow(); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); //First translucent status bar. window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); int statusBarHeight = getStatusBarHeight(activity); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams(); //如果已經為 ChildView 設定過了 marginTop, 再次呼叫時直接跳過 if (lp != null && lp.topMargin < statusBarHeight && lp.height != statusBarHeight) { //不預留系統空間 ViewCompat.setFitsSystemWindows(mChildView, false); lp.topMargin += statusBarHeight; mChildView.setLayoutParams(lp); } } View statusBarView = mContentView.getChildAt(0); if (statusBarView != null && statusBarView.getLayoutParams() != null && statusBarView.getLayoutParams().height == statusBarHeight) { //避免重複呼叫時多次新增 View statusBarView.setBackgroundColor(statusColor); return; } statusBarView = new View(activity); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight); statusBarView.setBackgroundColor(statusColor); //向 ContentView 中新增假 View mContentView.addView(statusBarView, 0, lp); } public String getUser_id(){ SharedPreferences sp; sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE); return sp.getString("id",""); } //獲取儲存的使用者名稱 public String getUser_name(){ SharedPreferences sp; sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE); return sp.getString("username",""); } //獲取儲存的密碼 public String getUser_password(){ SharedPreferences sp; sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE); return sp.getString("userpass",""); } public boolean getUser_remember(){ SharedPreferences sp; sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE); return sp.getBoolean("remember",false); } public void showToast(String content){ Toast.makeText(this,content,Toast.LENGTH_SHORT).show(); } }
二、啟動介面佈局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorLogin" android:orientation="vertical"> <ImageView android:id="@+id/imageView2" android:layout_width="120dp" android:layout_height="wrap_content" android:layout_gravity="center" android:scaleType="fitCenter" app:srcCompat="@drawable/ic_launcher" /> <TextView android:id="@+id/textView8" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#ffffff" android:textSize="18sp" android:gravity="center" android:padding="20dp" android:text="啟動" /> </LinearLayout>
三、修改啟動頁面(manifest)
<activity android:name=".Activity.StartActivity" android:theme="@style/AppTheme.Launcher"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
四、啟動頁面主題(styles.xml)
<style name="AppTheme.Launcher" parent="Theme.AppCompat.Light.NoActionBar">
<!-- 通過windowBackground可以設定背景色、背景圖片、能解析出圖片的XML檔案等-->
<!--<item name="android:windowBackground">@drawable/layer_launcher</item>-->
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@color/back_red</item>
<item name="android:windowIsTranslucent">true</item>
</style>
五、推薦一個動畫效果開源庫
相關推薦
Android啟動動畫實現
首先提一下實現機制:1.將manifest中launcher頁設為我們需要顯示的啟動頁面。2.在啟動動畫頁面中我們先載入我們需要的啟動頁面(動畫、文字、廣告等)。3.在啟動頁的activity中利用執行緒的postDelayed方法來延遲3s,3s後便執行跳轉到主介面或者登入
Android ListView動畫實現方法
rri pan 自己 data- src def popu 動畫 onclick 在Android中listview是最經常使用的控件之中的一個,可是有時候我們會認為千篇一律的listview看起來過於單調,於是就產生了listView動畫,listview載入了動畫會
Android啟動頁面實現版本檢查更新
res show execute 獲取app版本號 fly ppc imageload apk LV 1、引入模塊 CheckUpdateLibrary的github地址如下: https://github.com/qiangxi/CheckUpdateLibrary 打包
Android幀動畫實現,防OOM,比原生動畫集節約超過十倍的資源
2015年專案接到一個需求,實現一個嚮導動畫,這個動畫一共六十張圖片,當時使用的是全志A33的開發(512的記憶體),通過使用Android的動畫集實現,效果特別卡頓,然後想到這種方式來實現,效果很流暢
Android-利用動畫實現背景逐漸變暗
前言 之前寫了一篇,介紹利用Handler動態改變背景透明度從而達到變暗的效果。現在補充一種方法,使用動畫來實現相同的效果。 ValueAnimator 和 Interpolator 今天的主角就是這倆,關於ValueAnimator和Interpol
利用Android屬性動畫實現Banner控制元件
AnimationBanner特點: 1.實現原理及使用都很簡單 2.可靈活設定Banner數量,1張或N張 3.附帶Indicator小圓點指示器,並自動聯動 4.可靈活設定Indicator指
android複雜動畫實現途徑
最近做一個太陽光旋轉,光掃字的動畫效果,前期試了用ProgressBar用旋轉動畫作為背景,能實現效果,但是旋轉有卡頓現象和功耗太高問題,因此考慮其他方式解決。總結了一下此類動畫的實現途徑包括一下幾個
Android屬性動畫實現TextView類似支付寶餘額數字滾動
Demo下載連結 專案中的小需求,完成類似於支付寶餘額的數字滾動效果,找了網上的一個小demo,再加上郭嬸的關於屬性動畫的文章,整理一部分程式碼分享給有需要的人. 下面貼出封裝的TextView程式碼片段,主要是利用屬性動畫來更新TextView完成數字滾動
用動畫實現android app啟動介面的漸變效果
幾乎所有的app在啟動的時候都會有一個類似於開機畫面的東西,往往是一張圖片,上面寫著這個應用程式的提示文字,比如騰訊微博的啟動介面就是這樣的: 其實實現這種效果的原理很簡單,啟動介面也是一個activity,當時間到了之後銷燬這個activity,並啟動下一個a
android窗體動畫:activity啟動從底部向上滑動出現,關閉的時候從頂部向下滑動消失的動畫實現【轉】
在兩個Activity跳轉時,由於第二個Activity在啟動時載入了較多資料,就會在啟動之前出現一個短暫的黑屏時間,解決這個問題比較簡單的處理方法是將第二個Activity的主題設定成透明的,這樣在啟動第二個Activity時的黑屏就變成了顯示第一個Activity介面。這個分兩步完成: 第一步:xxx
android Title滑塊動畫實現(適合新聞client多種欄目的展示)
back content this ani == div .get tostring rep 先上效果圖,選擇不同的模塊,滑動會通過動畫形式滑過去,這樣的適合新聞client多種欄目的展示: 這麽寫Layout: <RelativeLayout xmlns:
Android ListView動畫特效實現原理及源代碼
stat 每一個 應該 所有 ner haar .get tde pri Android 動畫分三種,當中屬性動畫為我們最經常使用動畫,且能滿足項目中開發差點兒所有需求,google官方包支持3.0+。我們能夠引用三方包nineoldandr
android快速啟動動畫
android and tails sdn .net 快速 http .com tps http://blog.csdn.net/robert_cysy/article/details/72824513 https://www.cnblogs.com/404map/p/4
Xamarin.android Activity動畫切換效果實現
omx over tails detail ons too ide xamarin Coding http://blog.csdn.net/esunshine1985/article/details/44302903 1.在Resources——values下新建sty
Android 使用ActivityOptions實現Activity轉場動畫
之前一直都是用這種方式實現Activity的轉場動畫: // MainActivity overridePendingTransition(enterAnim, exitAnim); 從Android5.0之後,Google提供了一種新的方式來實現:ActivityOptions。
Android啟動頁面(閃屏頁面)的實現
閃屏頁面是指APP剛啟動時的頁面會自動跳轉到主頁面 單單實現閃屏頁面非常簡單。 閃屏介面的作用: 1.展示自己軟體的logo,口號標識語等, 2.作為廣告平臺,獲取利益 3.載入下一頁面(其他Activity或全域性)所需要的資料 4.檢查更新 效果展示 首先目錄
Android 幀動畫 的實現
文章目錄 1、幀動畫 2、檔案結構 3、activity_main.xml 檔案 4、frameanimation.xml 檔案 自定義的 動態檔案 5、ManiActivity 檔案
Android RecyclerView 詳解 RecyclerView的動畫實現(移除、新增、改變、移動)和自定義動畫的實現
一丶新增刪除時候的重新整理問題 先上一下效果圖吧 1.為了方便起見我們還是先新增三個按鈕分別實現新增刪除和改變 2.在Adapter中寫呼叫方法並進行重新整理 public void remove(int position){ list.re
Android -- 自定義ViewGroup+貝塞爾+屬性動畫實現仿QQ點贊效果
private void init(final Context context) { mStarDrawable = new ArrayList<>(); mInterpolators = new ArrayList<>(); mSt
Unity3D遊戲開發之“重寫Unity Android Splash,實現啟動無黑屏”
轉自:http://www.manew.com/thread-98428-1-1.html Splash設定相信搞unity的朋友都知道這個東西,就是遊戲啟動的時候的啟動畫面,在unity中如果不設定splash的話我們就能夠看到unity遊戲啟動的時候就會出現一張uni