Android拿來系列之萬能載入檢視 自定義彈窗
上一次關於彈窗的拿來篇是那種偏心選擇的,可以滑動有時差那種.
這次不同
//各種Dialog
compile 'com.flyco.dialog:FlycoDialog_Lib:[email protected]'
然後是自定義DiaLog 其實就那麼幾句 找到位置就行了 這裡主要改他的Gravity
public abstract class CustomBaseLoadingView<T extends CustomBaseLoadingView<T>> extends Dialog { /** mTag(日誌) */ protected String mTag; /** mContext(上下文) */ protected Context mContext; /** (DisplayMetrics)裝置密度 */ protected DisplayMetrics mDisplayMetrics; /** enable dismiss outside dialog(設定點選對話方塊以外區域,是否dismiss) */ protected boolean mCancel; /** dialog width scale(寬度比例) */ protected float mWidthScale = 1; /** dialog height scale(高度比例) */ protected float mHeightScale; /** mShowAnim(對話方塊顯示動畫) */ private BaseAnimatorSet mShowAnim; /** mDismissAnim(對話方塊消失動畫) */ private BaseAnimatorSet mDismissAnim; /** top container(最上層容器) */ protected LinearLayout mLlTop; /** container to control dialog height(用於控制對話方塊高度) */ protected LinearLayout mLlControlHeight; /** the child of mLlControlHeight you create.(創建出來的mLlControlHeight的直接子View) */ protected View mOnCreateView; /** is mShowAnim running(顯示動畫是否正在執行) */ private boolean mIsShowAnim; /** is DismissAnim running(消失動畫是否正在執行) */ private boolean mIsDismissAnim; /** max height(最大高度) */ protected float mMaxHeight; /** show Dialog as PopupWindow(像PopupWindow一樣展示Dialog) */ private boolean mIsPopupStyle; /** automatic dimiss dialog after given delay(在給定時間後,自動消失) */ private boolean mAutoDismiss; /** delay (milliseconds) to dimiss dialog(對話方塊消失延時時間,毫秒值) */ private long mAutoDismissDelay = 1500; private Handler mHandler = new Handler(Looper.getMainLooper()); /** * method execute order: * show:constrouctor---show---oncreate---onStart---onAttachToWindow * dismiss:dismiss---onDetachedFromWindow---onStop */ public CustomBaseLoadingView(Context context) { super(context); setDialogTheme(); mContext = context; mTag = getClass().getSimpleName(); setCanceledOnTouchOutside(true); Log.d(mTag, "constructor"); } public CustomBaseLoadingView(Context context, boolean isPopupStyle) { this(context); mIsPopupStyle = isPopupStyle; } /** set dialog theme(設定對話方塊主題) */ private void setDialogTheme() { requestWindowFeature(Window.FEATURE_NO_TITLE);// android:windowNoTitle getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));// android:windowBackground getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);// android:backgroundDimEnabled預設是true的 } /** * inflate layout for dialog ui and return (填充對話方塊所需要的佈局並返回) * <pre> * public View onCreateView() { * View inflate = View.inflate(mContext, R.layout.dialog_share, null); * return inflate; * } * </pre> */ public abstract View onCreateView(); public void onViewCreated(View inflate) { } /** set Ui data or logic opreation before attatched window(在對話方塊顯示之前,設定介面資料或者邏輯) */ public abstract void setUiBeforShow(); @Override protected void onCreate(Bundle savedInstanceState) { Log.d(mTag, "onCreate"); mDisplayMetrics = mContext.getResources().getDisplayMetrics(); mMaxHeight = mDisplayMetrics.heightPixels - StatusBarUtils.getHeight(mContext); // mMaxHeight = mDisplayMetrics.heightPixels; mLlTop = new LinearLayout(mContext); /******************自己改*****************/ mLlTop.setGravity(Gravity.CENTER_HORIZONTAL); mLlControlHeight = new LinearLayout(mContext); mLlControlHeight.setOrientation(LinearLayout.VERTICAL); mOnCreateView = onCreateView(); mLlControlHeight.addView(mOnCreateView); mLlTop.addView(mLlControlHeight); onViewCreated(mOnCreateView); if (mIsPopupStyle) { setContentView(mLlTop, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } else { setContentView(mLlTop, new ViewGroup.LayoutParams(mDisplayMetrics.widthPixels, (int) mMaxHeight)); } mLlTop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mCancel) { dismiss(); } } }); mOnCreateView.setClickable(true); } /** get actual created view(獲取實際建立的View) */ public View getCreateView() { return mOnCreateView; } /** * when dailog attached to window,set dialog width and height and show anim * (當dailog依附在window上,設定對話方塊寬高以及顯示動畫) */ @Override public void onAttachedToWindow() { super.onAttachedToWindow(); Log.d(mTag, "onAttachedToWindow"); setUiBeforShow(); int width; if (mWidthScale == 0) { width = ViewGroup.LayoutParams.WRAP_CONTENT; } else { width = (int) (mDisplayMetrics.widthPixels * mWidthScale); } int height; if (mHeightScale == 0) { height = ViewGroup.LayoutParams.WRAP_CONTENT; } else if (mHeightScale == 1) { // height = ViewGroup.LayoutParams.MATCH_PARENT; height = (int) mMaxHeight; } else { height = (int) (mMaxHeight * mHeightScale); } mLlControlHeight.setLayoutParams(new LinearLayout.LayoutParams(width, height)); if (mShowAnim != null) { mShowAnim.listener(new BaseAnimatorSet.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { mIsShowAnim = true; } @Override public void onAnimationRepeat(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { mIsShowAnim = false; delayDismiss(); } @Override public void onAnimationCancel(Animator animator) { mIsShowAnim = false; } }).playOn(mLlControlHeight); } else { BaseAnimatorSet.reset(mLlControlHeight); delayDismiss(); } } @Override public void setCanceledOnTouchOutside(boolean cancel) { this.mCancel = cancel; super.setCanceledOnTouchOutside(cancel); } @Override public void show() { Log.d(mTag, "show"); super.show(); } @Override protected void onStart() { super.onStart(); Log.d(mTag, "onStart"); } @Override protected void onStop() { super.onStop(); Log.d(mTag, "onStop"); } @Override public void onDetachedFromWindow() { super.onDetachedFromWindow(); Log.d(mTag, "onDetachedFromWindow"); } @Override public void dismiss() { Log.d(mTag, "dismiss"); if (mDismissAnim != null) { mDismissAnim.listener(new BaseAnimatorSet.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { mIsDismissAnim = true; } @Override public void onAnimationRepeat(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { mIsDismissAnim = false; superDismiss(); } @Override public void onAnimationCancel(Animator animator) { mIsDismissAnim = false; superDismiss(); } }).playOn(mLlControlHeight); } else { superDismiss(); } } /** dismiss without anim(無動畫dismiss) */ public void superDismiss() { super.dismiss(); } /** dialog anim by styles(動畫彈出對話方塊,style動畫資源) */ public void show(int animStyle) { Window window = getWindow(); window.setWindowAnimations(animStyle); show(); } /** show at location only valid for mIsPopupStyle true(指定位置顯示,只對isPopupStyle為true有效) */ public void showAtLocation(int gravity, int x, int y) { if (mIsPopupStyle) { Window window = getWindow(); WindowManager.LayoutParams params = window.getAttributes(); window.setGravity(gravity); params.x = x; params.y = y; } show(); } /** show at location only valid for mIsPopupStyle true(指定位置顯示,只對isPopupStyle為true有效) */ public void showAtLocation(int x, int y) { int gravity = Gravity.LEFT | Gravity.TOP;//Left Top (座標原點為右上角) showAtLocation(gravity, x, y); } /** set window dim or not(設定背景是否昏暗) */ public T dimEnabled(boolean isDimEnabled) { if (isDimEnabled) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } else { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } return (T)this; } /** set dialog width scale:0-1(設定對話方塊寬度,佔螢幕寬的比例0-1) */ public T widthScale(float widthScale) { this.mWidthScale = widthScale; return (T) this; } /** set dialog height scale:0-1(設定對話方塊高度,佔螢幕寬的比例0-1) */ public T heightScale(float heightScale) { mHeightScale = heightScale; return (T) this; } /** set show anim(設定顯示的動畫) */ public T showAnim(BaseAnimatorSet showAnim) { mShowAnim = showAnim; return (T) this; } /** set dismiss anim(設定隱藏的動畫) */ public T dismissAnim(BaseAnimatorSet dismissAnim) { mDismissAnim = dismissAnim; return (T) this; } /** automatic dimiss dialog after given delay(在給定時間後,自動消失) */ public T autoDismiss(boolean autoDismiss) { mAutoDismiss = autoDismiss; return (T) this; } /** set dealy (milliseconds) to dimiss dialog(對話方塊消失延時時間,毫秒值) */ public T autoDismissDelay(long autoDismissDelay) { mAutoDismissDelay = autoDismissDelay; return (T) this; } private void delayDismiss() { if (mAutoDismiss && mAutoDismissDelay > 0) { mHandler.postDelayed(new Runnable() { @Override public void run() { dismiss(); } }, mAutoDismissDelay); } } @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (mIsDismissAnim || mIsShowAnim || mAutoDismiss) { return true; } return super.dispatchTouchEvent(ev); } @Override public void onBackPressed() { if (mIsDismissAnim || mIsShowAnim || mAutoDismiss) { return; } super.onBackPressed(); } /** dp to px */ protected int dp2px(float dp) { final float scale = mContext.getResources().getDisplayMetrics().density; return (int) (dp * scale + 0.5f); } }
//穿插個loading庫
https://github.com/zyao89/ZLoading
compile 'com.zyao89:zloading:1.1.2'
XML
Mainac<?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:gravity="center" android:orientation="vertical"> <com.zyao89.view.zloading.ZLoadingView android:layout_width="wrap_content" android:layout_height="wrap_content" app:z_color="@color/colorAccent" app:z_type="CircleBuilder" /> </LinearLayout>
final CustomLoadingDialog_1 customLoadingDialog_1 = new CustomLoadingDialog_1(this); customLoadingDialog_1.show(); new CountDownTimer(3000,1000){ @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { customLoadingDialog_1.dismiss(); } }.start();
相關推薦
Android拿來系列之萬能載入檢視 自定義彈窗
上一次關於彈窗的拿來篇是那種偏心選擇的,可以滑動有時差那種.這次不同//各種Dialog compile 'com.flyco.dialog:FlycoDialog_Lib:[email protected]'然後是自定義DiaLog 其實就那麼幾句 找到位
Android拿來系列之萬能圖片處理方案
Glide 匯入依賴 //圓形 矩形圖片 邊框 compile 'cn.gavinliu.android.lib:ShapedImageView:0.8.5' //Glide compile 'com.github.bumptech.gli
碼農裝13寶典系列之五:Ubuntu自定義字型縮放級別
目前主流顯示器都有一個很高的解析度,而使用預設的解析度會使字型顯示過小,單純地調整解析度又容易讓字看起來發虛。 系統提供了一個字型縮放級別調整的功能。Windows初始化時就已經為使用者設定好了,而Ubuntu只有兩個選項:100%、200%,顯然不能滿足需求。 那怎麼辦? 這裡需要
Android Studio 配置系列(一):自定義程式碼註釋
1. 自定義檔案頭註釋 依次點選File -> Settings ->Editor ->File and Code Templates,在詳細展示視窗點選includes選項卡,找到FileHeader點選,在編輯視窗輸入自定義的註釋模板即可
Android--萬能自定義彈窗
使用的是AlertDialog 自定義彈窗呢,就是一個介面放在了AlertDialog容器彈框上。 第一步:寫好你的介面 (在layout下建立system_admin_psw_alert_dialog.xml) <?xml version="1.0
React native 自定義彈窗(android使用原生ios彈窗)
android端執行效果圖(ios同樣適用): 1.自定義彈窗原始碼: import React, { Component } from 'react'; import { StyleSheet, Text, View, Modal
android影象處理系列之五--給圖片新增邊框(中)
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
jvm系列之-gc日誌檢視
在上一篇中我們介紹的有引數的設定,那我們要了解不同的引數對於程式的影響和對於調優的影響,這個時候我們就需要檢視gc日誌來看我們設定的引數是否合理,這一章節中我們就來檢視gc日誌 一、新生代和老年代的比值對效能的影響 Map map = new HashMap<&
android影象處理系列之六--給圖片新增邊框(下)-圖片疊加
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
android影象處理系列之四--給圖片新增邊框(上)
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
Android功耗評測系列之——軟體評測方案原理
軟體評測方案也有很多種,但核心原理都是同一個。 軟體評測方案中,所有Android功耗的統計都是通過程式碼進行估算,沒有任何實體電路和硬體裝置參與統計彙報。 這個配置檔案儲存在Android裝置
android影象處理系列之七--圖片塗鴉,水印-圖片疊加
圖片塗鴉和水印其實是一個功能,實現的方式是一樣的,就是一張大圖片和一張小點圖片疊加即可。前面在android影象處理系列之六--給圖片新增邊框(下)-圖片疊加中也講到了圖片疊加,裡面實現的原理是直接操作畫素點。下面給出別外一種方式讓圖片疊加--用Canvas處理圖片,canva
Android電源管理系列之PowerManagerService(二)
WakeLock機制 PowerManager.WakeLock 為了延長電池的使用壽命,Android裝置會在一段時間後使螢幕變暗,然後關閉螢幕顯示,直至停止CPU進入休眠。WakeLock是Android提供的喚醒鎖機制,用來保持CPU執行或避免螢幕變暗/關閉以及避免鍵盤背光燈熄滅
Android電源管理系列之PowerManagerService(一)
PowerManagerService 提供Android系統的電源管理服務,主要功能是控制系統待機狀態,螢幕顯示,亮度調節,光線/距離感測器的控制等。 相關程式碼在以下檔案中 frameworks/base/services/java/com/androi
Android面試總結系列之面試技巧
文章目錄 面試官:Android動畫用過嗎? 我:用過一些簡單的。 面試官:那就簡單講一下吧!!! 本篇文章將根據我這些年面試和被面試的經驗來總結面試技巧,給各位迷茫的同學做個參考。 我認為面試問題一般都可以被分兩大類: 一類是公司專
[gitbook] Android框架分析系列之Android stagefright框架
請支援作者原創: https://mr-cao.gitbooks.io/Android/content 點選開啟連結 本文以Android6.0系統原始碼為基礎,分析Android
Android使用者介面設計之建立列表檢視程式
列表檢視(ListView)是Android平臺下用於顯示不定數量的資料最有用的檢視控制元件之一。在這個教程中,我們將向你展示如何使用ListView來瀏覽文章列表。 在之前的文章中,你看到了許多關於不同佈局控制元件的教程。應用程式本身非常簡單:它將顯示文章標題列表,當
Vue系列之 => 命名檢視實現經典佈局
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <meta charset="utf-8"> 6 <meta name="viewport" content="width=de
Android控制元件系列之RadioButton與RadioGroup的基本使用
RadioButton即單選框,是一種基礎的UI控制元件。RadioGroup為我們提供了RadioButton單選按鈕的容器,RadioButton通常放於RadioGroup容器中進行使用。RadioButton的選中狀態,在xml檔案中可以使用android:chec
Android訪問網路系列之--服務端返回XML或JSON格式資料,Android 進行解析並顯示
例子說明:使用者通過訪問web資源的最新電影資訊,伺服器端生成XML或JSON格式資料,返回Android客戶端進行顯示。 此案例開發需要兩個方面 WEB開發和android開發. 一.web開發相對比較簡單,只是模擬一下 相關程式碼如下: 1.實體Bean package ygc.yxb.domain