日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

【Android应用开发】EasyDialog 源码解析

發布時間:2025/6/17 Android 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Android应用开发】EasyDialog 源码解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.



示例源碼下載 :?http://download.csdn.net/detail/han1202012/9115227


EasyDialog 簡介 :?

-- 作用 : 用于在界面進行一些介紹, 說明;

-- 效果圖 :?







一. EasyDialog 源碼解析



1. 實現原理




實現原理 :?

-- EasyDialog 效果 :?在點擊后, 會從屏幕外飛入對話框, 飛入恰好能夠正好處于特定 View 組件的上方 或者下方;

-- 本質 : 點擊按鈕彈出的對話框會填充整個屏幕, 背景設置成透明的, 然后會計算組件坐標, 記錄坐標位置, 再在彈出的整個對話框中 繪制一個 帶小三角對話框的布局, 并讓其執行動畫;



2. 動畫效果總結



(1) 動畫實現核心代碼


對話框顯示小時動畫效果實現代碼片段 :?

private AnimatorSet animatorSetForDialogShow;private AnimatorSet animatorSetForDialogDismiss;private List<Animator> objectAnimatorsForDialogShow;private List<Animator> objectAnimatorsForDialogDismiss;/*** 對話框顯示的動畫*/private void onDialogShowing() {if (animatorSetForDialogShow != null&& objectAnimatorsForDialogShow != null&& objectAnimatorsForDialogShow.size() > 0) {animatorSetForDialogShow.playTogether(objectAnimatorsForDialogShow);animatorSetForDialogShow.start();}}/*** 對話框消失的動畫*/private void onDialogDismiss() {if (animatorSetForDialogDismiss.isRunning()) {return;}if (animatorSetForDialogDismiss != null&& objectAnimatorsForDialogDismiss != null&& objectAnimatorsForDialogDismiss.size() > 0) {animatorSetForDialogDismiss.playTogether(objectAnimatorsForDialogDismiss);animatorSetForDialogDismiss.start();animatorSetForDialogDismiss.addListener(new Animator.AnimatorListener() {@Overridepublic void onAnimationStart(Animator animation) {}@Overridepublic void onAnimationEnd(Animator animation) {dialog.dismiss();}@Overridepublic void onAnimationCancel(Animator animation) {}@Overridepublic void onAnimationRepeat(Animator animation) {}});} else {dialog.dismiss();}}

(2) AnimatorSet 簡介


AnimationSet 與 AnimatorSet 區別 : AnimatorSet 功能較強;

--?AnimatorSet : 執行的是 Animator 動畫, 主要是靠改變視圖屬性產生動畫效果;

--?AnimationSet : 執行的是 Animation 動畫, 主要是靠改變視圖的外觀實現動畫效果;?


Animator 簡介 : Animator 也是一種動畫, 可以由用戶執行開始, 中斷執行, 還可以設置動畫執行監聽器;


AnimatorSet 簡介?:?

-- 功能 : 按照特定順序執行一個 Animator 動畫集合, 動畫可以一起執行, 先后執行, 延遲執行;

-- 添加動畫 : 有兩種方式向 AnimatorSet 中添加動畫, 調用?playTogether() 或者 playSequentially() 可以一次性向其中添加一個 動畫集合, 調用?AnimatorSet.Builder 中得 play() 方法, 可以一個一個地向其中添加動畫;




3. 坐標計算時機



坐標計算 : 計算坐標時需要獲取組件的寬 和 高, 下面的代碼中可以獲取寬高, 獲取到寬高后, 其坐標自然就計算好了;

-- 獲取屏幕寬高代碼 : 在其中的 onGlobalLayout 方法中可以獲取其寬高;

/** 獲取對話框的寬 高* 不是真的獲取對話框的寬高, 是在對話框被構建繪制到 布局中時 * 利用這個時機去設置對話框位置*/ViewTreeObserver viewTreeObserver = dialogView.getViewTreeObserver();viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {@Overridepublic void onGlobalLayout() {// 當View可以獲取寬高的時候,設置view的位置relocation(location);}});


4. 屏幕填充設置



設置是否填充屏幕 :?

/*** 設置是否填充屏幕,如果不填充就適應布局內容的寬度,顯示內容的位置會盡量隨著三角形的位置居中*/public EasyDialog setMatchParent(boolean matchParent) {ViewGroup.LayoutParams layoutParams = llContent.getLayoutParams();layoutParams.width = matchParent ? ViewGroup.LayoutParams.MATCH_PARENT: ViewGroup.LayoutParams.WRAP_CONTENT;llContent.setLayoutParams(layoutParams);return this;}-- 填充屏幕樣式 : 可以看到 填充全屏, 左右只留下了 margin;


-- 不填充屏幕樣式 : 不會橫向充滿屏幕;







二. EasyDialog 主要源碼



1. EasyDialog 包裝類



package cn.org.octopus.easydialog;import java.util.ArrayList; import java.util.List;import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.RotateDrawable; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.Toast;public class EasyDialog {/*** 上下文對象*/private Context context;/*** 內容在三角形上面*/public static final int GRAVITY_TOP = 0;/*** 內容在三角形下面*/public static final int GRAVITY_BOTTOM = 1;/*** 對話框本身*/private Dialog dialog;/*** 坐標*/private int[] location;/*** 提醒框位置*/private int gravity;/*** 外面傳遞進來的View*/private View contentView;/*** 三角形*/private ImageView ivTriangle;/*** 用來放外面傳遞進來的View*/private LinearLayout llContent;/*** 觸摸外面,是否關閉對話框*/private boolean touchOutsideDismiss;/*** 提示框所在的容器*/private RelativeLayout rlOutsideBackground;public EasyDialog(Context context) {initDialog(context);}/*** 初始化* @param context*/private void initDialog(final Context context) {this.context = context;/** 說明傳入的對象是一個 Activity* 獲取 Activity 的布局加載器*/LayoutInflater layoutInflater = ((Activity) context).getLayoutInflater();//要顯示的對話框布局View dialogView = layoutInflater.inflate(R.layout.layout_dialog, null);/** 獲取對話框的寬 高* 不是真的獲取對話框的寬高, 是在對話框被構建繪制到 布局中時 * 利用這個時機去設置對話框位置*/ViewTreeObserver viewTreeObserver = dialogView.getViewTreeObserver();viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {@Overridepublic void onGlobalLayout() {// 當View可以獲取寬高的時候,設置view的位置relocation(location);}});//初始化對話框所在的容器rlOutsideBackground = (RelativeLayout) dialogView.findViewById(R.id.rlOutsideBackground);//為容器設置點擊事件, 一旦點擊, 就讓對話框消失rlOutsideBackground.setOnTouchListener(new View.OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {//關閉對話框前提 標志位true, 對話框不為 nullif (touchOutsideDismiss && dialog != null) {onDialogDismiss();}return false;}});//對話框上部 或者 下部的 小三角形ivTriangle = (ImageView) dialogView.findViewById(R.id.ivTriangle);//對話框的長條llContent = (LinearLayout) dialogView.findViewById(R.id.llContent);//創建對話框dialog = new Dialog(context,isFullScreen() ? android.R.style.Theme_Translucent_NoTitleBar_Fullscreen: android.R.style.Theme_Translucent_NoTitleBar);//設置對話框布局dialog.setContentView(dialogView);//對話框顯示動畫animatorSetForDialogShow = new AnimatorSet();//對話框消失動畫animatorSetForDialogDismiss = new AnimatorSet();objectAnimatorsForDialogShow = new ArrayList<>();objectAnimatorsForDialogDismiss = new ArrayList<>();//初始化默認值initData();}/*** 初始化默認值*/private void initData() {this.setLocation(new int[] { 0, 0 }) //設置默認位置.setGravity(GRAVITY_BOTTOM) //設置三角形位置 (上 或者 下).setTouchOutsideDismiss(true) //設置是否可以點擊對話框消失.setOutsideColor(Color.TRANSPARENT) //設置對話框外部背景顏色.setBackgroundColor(Color.BLUE) //設置對話框背景.setMatchParent(true) //設置是否填充全屏.setMarginLeftAndRight(24, 24); //設置左右margin}/*** 設置提示框中要顯示的內容*/public EasyDialog setLayout(View layout) {if (layout != null) {this.contentView = layout;}return this;}/*** 設置提示框中要顯示的內容的布局Id*/public EasyDialog setLayoutResourceId(int layoutResourceId) {View view = ((Activity) context).getLayoutInflater().inflate(layoutResourceId, null);setLayout(view);return this;}/*** 設置三角形所在的位置* * @param location* 傳入 x y 坐標* @return*/public EasyDialog setLocation(int[] location) {this.location = location;return this;}/*** 設置三角形位置* -- x 坐標 : x坐標值為attachedView所在屏幕位置的中心* -- y 坐標 : y坐標值依據當前的gravity,如果gravity是top,則為控件上方的y值,如果是bottom,則為控件的下方的y值** @param attachedView* 在哪個View顯示提示信息*/public EasyDialog setLocationByAttachedView(View attachedView) {if (attachedView != null) {//為成員變量賦值this.attachedView = attachedView;//該數組存儲三角形位置數據int[] attachedViewLocation = new int[2];// 獲取 attachedView 的位置, 左上角位置attachedView.getLocationOnScreen(attachedViewLocation);//計算 x 坐標, 即 attachedView 的中間位置attachedViewLocation[0] = attachedViewLocation[0]+ attachedView.getWidth() / 2;//計算 y 坐標switch (gravity) {case GRAVITY_BOTTOM://如果三角形在下, 即三角形位置是 attachedView 的下方attachedViewLocation[1] = attachedViewLocation[1]+ attachedView.getHeight();break;case GRAVITY_TOP://如果三角形在上, 即三角形位置是 attachedView 的上方, 即默認值break;}//設置三角形位置setLocation(attachedViewLocation);}return this;}/*** 對話框所依附的View* */private View attachedView = null;/*** 設置顯示的內容在上方還是下方,如果設置錯誤,默認是在下方*/public EasyDialog setGravity(int gravity) {//如果設置的位置值 既不是上 也不是下, 默認為下if (gravity != GRAVITY_BOTTOM && gravity != GRAVITY_TOP) {gravity = GRAVITY_BOTTOM;}//設置到成員變量中this.gravity = gravity;//設置三角形的圖片, switch (this.gravity) {case GRAVITY_BOTTOM:ivTriangle.setBackgroundResource(R.drawable.triangle_bottom);break;case GRAVITY_TOP:ivTriangle.setBackgroundResource(R.drawable.triangle_top);break;}//對話框 主題長條的 ViewllContent.setBackgroundResource(R.drawable.round_corner_bg);// 如果用戶調用setGravity()之前就調用過setLocationByAttachedView,需要再調用一次setLocationByAttachedViewif (attachedView != null) {this.setLocationByAttachedView(attachedView);}//設置對話框顏色this.setBackgroundColor(backgroundColor);return this;}/*** 設置是否填充屏幕,如果不填充就適應布局內容的寬度,顯示內容的位置會盡量隨著三角形的位置居中*/public EasyDialog setMatchParent(boolean matchParent) {ViewGroup.LayoutParams layoutParams = llContent.getLayoutParams();layoutParams.width = matchParent ? ViewGroup.LayoutParams.MATCH_PARENT: ViewGroup.LayoutParams.WRAP_CONTENT;llContent.setLayoutParams(layoutParams);return this;}/*** 距離屏幕左右的邊距* 設置對話框所在的整個容器的布局*/public EasyDialog setMarginLeftAndRight(int left, int right) {RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) llContent.getLayoutParams();layoutParams.setMargins(left, 0, right, 0);llContent.setLayoutParams(layoutParams);return this;}/*** 設置觸摸對話框外面,對話框是否消失*/public EasyDialog setTouchOutsideDismiss(boolean touchOutsideDismiss) {this.touchOutsideDismiss = touchOutsideDismiss;return this;}/*** 設置提醒框外部區域的顏色*/public EasyDialog setOutsideColor(int color) {rlOutsideBackground.setBackgroundColor(color);return this;}private int backgroundColor;/*** 設置對話框的顏色* <p/>* 三角形的圖片是layer-list里面嵌套一個RotateDrawable,在設置顏色的時候需要特別處理* http://stackoverflow.* com/questions/24492000/set-color-of-triangle-on-run-time* http://stackoverflow* .com/questions/16636412/change-shape-solid-color-at-runtime* -inside-drawable-xml-used-as-background*/public EasyDialog setBackgroundColor(int color) {backgroundColor = color;LayerDrawable drawableTriangle = (LayerDrawable) ivTriangle.getBackground();GradientDrawable shapeTriangle = (GradientDrawable) (((RotateDrawable) drawableTriangle.findDrawableByLayerId(R.id.shape_id)).getDrawable());if (shapeTriangle != null) {shapeTriangle.setColor(color);} else {Toast.makeText(context, "shape is null", Toast.LENGTH_SHORT).show();}GradientDrawable drawableRound = (GradientDrawable) llContent.getBackground();if (drawableRound != null) {drawableRound.setColor(color);}return this;}/*** 顯示提示框* * 這個對話框 整個填充全屏, 顯示后, 執行里面的 小對話框 (小三角 和 提示框內容)*/public EasyDialog show() {if (dialog != null) {if (contentView == null) {throw new RuntimeException("您是否未調用setLayout()或者setLayoutResourceId()方法來設置要顯示的內容呢?");}//設置對話框顯示的內容llContent.addView(contentView);//顯示整個對話框dialog.show();//顯示小對話框的動畫onDialogShowing();}return this;}/*** 顯示對話框的View的parent,如果想自己寫動畫,可以獲取這個實例來寫動畫** */public View getTipViewInstance() {return rlOutsideBackground.findViewById(R.id.rlParentForAnimate);}/** 橫向 */public static final int DIRECTION_X = 0;/** 縱向 */public static final int DIRECTION_Y = 1;/*** 水平動畫** @param direction* 動畫的方向* @param duration* 動畫執行的時間長度* @param values* 動畫移動的位置* */public EasyDialog setAnimationTranslationShow(int direction, int duration,float... values) {return setAnimationTranslation(true, direction, duration, values);}/*** 水平動畫** @param direction* 動畫的方向* @param duration* 動畫執行的時間長度* @param values* 動畫移動的位置* */public EasyDialog setAnimationTranslationDismiss(int direction,int duration, float... values) {return setAnimationTranslation(false, direction, duration, values);}private EasyDialog setAnimationTranslation(boolean isShow, int direction,int duration, float... values) {if (direction != DIRECTION_X && direction != DIRECTION_Y) {direction = DIRECTION_X;}String propertyName = "";switch (direction) {case DIRECTION_X:propertyName = "translationX";break;case DIRECTION_Y:propertyName = "translationY";break;}ObjectAnimator animator = ObjectAnimator.ofFloat(rlOutsideBackground.findViewById(R.id.rlParentForAnimate),propertyName, values).setDuration(duration);if (isShow) {objectAnimatorsForDialogShow.add(animator);} else {objectAnimatorsForDialogDismiss.add(animator);}return this;}/*** 對話框出現時候的漸變動畫** @param duration* 動畫執行的時間長度* @param values* 動畫移動的位置* */public EasyDialog setAnimationAlphaShow(int duration, float... values) {return setAnimationAlpha(true, duration, values);}/*** 對話框消失時候的漸變動畫** @param duration* 動畫執行的時間長度* @param values* 動畫移動的位置* */public EasyDialog setAnimationAlphaDismiss(int duration, float... values) {return setAnimationAlpha(false, duration, values);}private EasyDialog setAnimationAlpha(boolean isShow, int duration,float... values) {ObjectAnimator animator = ObjectAnimator.ofFloat(rlOutsideBackground.findViewById(R.id.rlParentForAnimate),"alpha", values).setDuration(duration);if (isShow) {objectAnimatorsForDialogShow.add(animator);} else {objectAnimatorsForDialogDismiss.add(animator);}return this;}private AnimatorSet animatorSetForDialogShow;private AnimatorSet animatorSetForDialogDismiss;private List<Animator> objectAnimatorsForDialogShow;private List<Animator> objectAnimatorsForDialogDismiss;/*** 對話框顯示的動畫*/private void onDialogShowing() {if (animatorSetForDialogShow != null&& objectAnimatorsForDialogShow != null&& objectAnimatorsForDialogShow.size() > 0) {animatorSetForDialogShow.playTogether(objectAnimatorsForDialogShow);animatorSetForDialogShow.start();}}/*** 對話框消失的動畫*/private void onDialogDismiss() {if (animatorSetForDialogDismiss.isRunning()) {return;}if (animatorSetForDialogDismiss != null&& objectAnimatorsForDialogDismiss != null&& objectAnimatorsForDialogDismiss.size() > 0) {animatorSetForDialogDismiss.playTogether(objectAnimatorsForDialogDismiss);animatorSetForDialogDismiss.start();animatorSetForDialogDismiss.addListener(new Animator.AnimatorListener() {@Overridepublic void onAnimationStart(Animator animation) {}@Overridepublic void onAnimationEnd(Animator animation) {dialog.dismiss();}@Overridepublic void onAnimationCancel(Animator animation) {}@Overridepublic void onAnimationRepeat(Animator animation) {}});} else {dialog.dismiss();}}/*** 關閉提示框*/public void dismiss() {if (dialog != null && dialog.isShowing()) {onDialogDismiss();}}/*** 根據x,y,重新設置控件的位置* * 因為setX setY為0的時候,都是在狀態欄以下的,所以app不是全屏的話,需要扣掉狀態欄的高度*/private void relocation(int[] location) {ivTriangle.setX(location[0] - ivTriangle.getWidth() / 2);ivTriangle.setY(location[1] - ivTriangle.getHeight() / 2- (isFullScreen() ? 0.0f : getStatusBarHeight()));// 因為三角形是通過XML繪制出來的,可以到activity_tip_overlay.xml中把三角形的那個ImageView背景設置一下,就知道什么情況了。所以需要減掉一半的高度switch (gravity) {case GRAVITY_BOTTOM:llContent.setY(location[1] - ivTriangle.getHeight() / 2- (isFullScreen() ? 0.0f : getStatusBarHeight())+ ivTriangle.getHeight());break;case GRAVITY_TOP:llContent.setY(location[1] - llContent.getHeight()- (isFullScreen() ? 0.0f : getStatusBarHeight())- ivTriangle.getHeight() / 2);break;}// 顯示內容的區域往三角形靠攏int triangleCenterX = (int) (ivTriangle.getX() + ivTriangle.getWidth() / 2);// 三角形的中心點int contentWidth = llContent.getWidth();int rightMargin = getScreenWidth() - triangleCenterX;// 三角形中心距離屏幕右邊的距離int leftMargin = getScreenWidth() - rightMargin;// 三角形中心距離屏幕左邊的距離RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) llContent.getLayoutParams();int availableLeftMargin = leftMargin - layoutParams.leftMargin;// 左邊可用的距離int availableRightMargin = rightMargin - layoutParams.rightMargin;// 右邊可用的距離int x = 0;if (contentWidth / 2 <= availableLeftMargin&& contentWidth / 2 <= availableRightMargin)// 左右兩邊有足夠的距離{x = triangleCenterX - contentWidth / 2;} else {if (availableLeftMargin <= availableRightMargin)// 判斷三角形在屏幕中心的左邊{x = layoutParams.leftMargin;} else// 三角形在屏幕中心的右邊{x = getScreenWidth()- (contentWidth + layoutParams.rightMargin);}}llContent.setX(x);}/*** 獲取屏幕的寬度* */private int getScreenWidth() {DisplayMetrics metrics = context.getResources().getDisplayMetrics();return metrics.widthPixels;}/*** 獲取狀態欄的高度*/private int getStatusBarHeight() {int result = 0;int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");if (resourceId > 0) {result = context.getResources().getDimensionPixelSize(resourceId);}return result;}/*** 判斷下當前要顯示對話框的Activity是否是全屏*/public boolean isFullScreen() {int flg = ((Activity) context).getWindow().getAttributes().flags;boolean flag = false;if ((flg & 1024) == 1024) {flag = true;}return flag;}/*** 設置是否可以按返回按鈕取消* */public EasyDialog setCancelable(boolean cancelable) {dialog.setCancelable(cancelable);return this;} }

2. EasyDialog 調用


package cn.org.octopus.easydialog;import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.MotionEvent; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.Toast;public class MainActivity extends ActionBarActivity implements View.OnClickListener {private RelativeLayout rlBackground;private Button btnTopLeft;private Button btnTopRight;private Button btnMiddleTop;private Button btnMiddleBottom;private Button btnBottomLeft;private Button btnBottomRight;@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);iniComponent();}private void iniComponent(){rlBackground = (RelativeLayout)findViewById(R.id.rlBackground);btnTopLeft = (Button) findViewById(R.id.btnTopLeft);btnTopRight = (Button) findViewById(R.id.btnTopRight);btnMiddleTop = (Button) findViewById(R.id.btnMiddleTop);btnMiddleBottom = (Button) findViewById(R.id.btnMiddleBottom);btnBottomLeft = (Button) findViewById(R.id.btnBottomLeft);btnBottomRight = (Button) findViewById(R.id.btnBottomRight);btnTopLeft.setOnClickListener(this);btnTopRight.setOnClickListener(this);btnMiddleTop.setOnClickListener(this);btnMiddleBottom.setOnClickListener(this);btnBottomLeft.setOnClickListener(this);btnBottomRight.setOnClickListener(this);rlBackground.setOnTouchListener(new View.OnTouchListener(){@Overridepublic boolean onTouch(View v, MotionEvent event){int[] location = new int[2];location[0] = (int)event.getX();location[1] = (int)event.getY();location[1] = location[1] + getActionBarHeight() + getStatusBarHeight();Toast.makeText(MainActivity.this, "x:" + location[0] + " y:" + location[1], Toast.LENGTH_SHORT).show();new EasyDialog(MainActivity.this).setLayoutResourceId(R.layout.layout_tip_content_horizontal).setBackgroundColor(MainActivity.this.getResources().getColor(R.color.background_color_black)).setLocation(location).setGravity(EasyDialog.GRAVITY_TOP).setTouchOutsideDismiss(true).setMatchParent(false).setMarginLeftAndRight(24, 24).setOutsideColor(MainActivity.this.getResources().getColor(R.color.outside_color_gray)).show();return false;}});}@Overridepublic void onClick(View v){switch (v.getId()){case R.id.btnTopLeft:View view = this.getLayoutInflater().inflate(R.layout.layout_tip_content_horizontal, null);new EasyDialog(MainActivity.this).setLayout(view).setBackgroundColor(MainActivity.this.getResources().getColor(R.color.background_color_black)).setLocationByAttachedView(btnTopLeft).setGravity(EasyDialog.GRAVITY_BOTTOM).setAnimationTranslationShow(EasyDialog.DIRECTION_X, 1000, -600, 100, -50, 50, 0).setAnimationAlphaShow(1000, 0.3f, 1.0f).setAnimationTranslationDismiss(EasyDialog.DIRECTION_X, 500, -50, 800).setAnimationAlphaDismiss(500, 1.0f, 0.0f).setTouchOutsideDismiss(true).setMatchParent(true).setMarginLeftAndRight(24, 24).setOutsideColor(MainActivity.this.getResources().getColor(R.color.outside_color_trans)).show();break;case R.id.btnTopRight:new EasyDialog(MainActivity.this).setLayoutResourceId(R.layout.layout_tip_image_text).setGravity(EasyDialog.GRAVITY_BOTTOM).setBackgroundColor(MainActivity.this.getResources().getColor(R.color.background_color_black)).setLocationByAttachedView(btnTopRight).setAnimationTranslationShow(EasyDialog.DIRECTION_X, 350, 400, 0).setAnimationTranslationDismiss(EasyDialog.DIRECTION_X, 350, 0, 400).setTouchOutsideDismiss(true).setMatchParent(false).setMarginLeftAndRight(24, 24).setOutsideColor(MainActivity.this.getResources().getColor(R.color.outside_color_trans)).show();break;case R.id.btnMiddleTop:new EasyDialog(MainActivity.this).setLayoutResourceId(R.layout.layout_tip_content_horizontal).setBackgroundColor(MainActivity.this.getResources().getColor(R.color.background_color_blue)).setLocationByAttachedView(btnMiddleTop).setAnimationTranslationShow(EasyDialog.DIRECTION_Y, 1000, -800, 100, -50, 50, 0).setAnimationTranslationDismiss(EasyDialog.DIRECTION_Y, 500, 0, -800).setGravity(EasyDialog.GRAVITY_TOP).setTouchOutsideDismiss(true).setMatchParent(false).setMarginLeftAndRight(24, 24).setOutsideColor(MainActivity.this.getResources().getColor(R.color.outside_color_pink)).show();break;case R.id.btnMiddleBottom:new EasyDialog(MainActivity.this).setLayoutResourceId(R.layout.layout_tip_content_horizontal).setGravity(EasyDialog.GRAVITY_BOTTOM).setBackgroundColor(MainActivity.this.getResources().getColor(R.color.background_color_brown)).setLocationByAttachedView(btnMiddleBottom).setAnimationTranslationShow(EasyDialog.DIRECTION_Y, 1000, 800, -100, -50, 50, 0).setAnimationTranslationDismiss(EasyDialog.DIRECTION_Y, 500, 0, 800).setAnimationAlphaShow(1000, 0.3f, 1.0f).setTouchOutsideDismiss(true).setMatchParent(true).setMarginLeftAndRight(24, 24).setOutsideColor(MainActivity.this.getResources().getColor(R.color.outside_color_gray)).show();break;case R.id.btnBottomLeft:new EasyDialog(MainActivity.this).setLayoutResourceId(R.layout.layout_tip_text).setBackgroundColor(MainActivity.this.getResources().getColor(R.color.background_color_pink)).setLocationByAttachedView(btnBottomLeft).setGravity(EasyDialog.GRAVITY_TOP).setAnimationAlphaShow(600, 0.0f, 1.0f).setAnimationAlphaDismiss(600, 1.0f, 0.0f).setTouchOutsideDismiss(true).setMatchParent(false).setMarginLeftAndRight(24, 24).setOutsideColor(MainActivity.this.getResources().getColor(R.color.outside_color_trans)).show();break;case R.id.btnBottomRight:new EasyDialog(MainActivity.this).setLayoutResourceId(R.layout.layout_tip_image_text).setBackgroundColor(MainActivity.this.getResources().getColor(R.color.background_color_yellow)).setLocationByAttachedView(btnBottomRight).setGravity(EasyDialog.GRAVITY_TOP).setAnimationTranslationShow(EasyDialog.DIRECTION_X, 300, 400, 0).setAnimationTranslationShow(EasyDialog.DIRECTION_Y, 300, 400, 0).setAnimationTranslationDismiss(EasyDialog.DIRECTION_X, 300, 0, 400).setAnimationTranslationDismiss(EasyDialog.DIRECTION_Y, 300, 0, 400).setTouchOutsideDismiss(true).setMatchParent(false).setMarginLeftAndRight(24, 24).setOutsideColor(MainActivity.this.getResources().getColor(R.color.outside_color_trans)).show();break;}}private int getStatusBarHeight(){int result = 0;int resourceId = this.getResources().getIdentifier("status_bar_height", "dimen", "android");if (resourceId > 0){result = this.getResources().getDimensionPixelSize(resourceId);}return result;}private int getActionBarHeight(){return this.getSupportActionBar().getHeight();} }


總結

以上是生活随笔為你收集整理的【Android应用开发】EasyDialog 源码解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。