欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android巧用DecorView實現(xiàn)對話框功能

 更新時間:2017年04月08日 10:03:39   作者:大批  
本篇文章主要介紹了Android巧用DecorView實現(xiàn)對話框功能,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

如果還不知道DecorView,那也沒有什么關(guān)系 ^_^

先來看看實現(xiàn)的效果

實現(xiàn)的大致思路

  1. 首先需要明白什么是DecorView,他是android中界面的根布局。其實android的activity界面整個就是一個控件樹,DecorView是根節(jié)點,DecorView的孩子節(jié)點就是一個LinearLayout,這個LinearLayout的孩子系節(jié)點就包括狀態(tài)欄 + 和我們自己寫的布局
  2. DecorView是FramLayout的子類(可以從源碼中看到)
  3. 既然DecorView是根節(jié)點,而且還是FrameLayout,所以我們可以把我們自己的布局 添加到DecorView 或者 從DecorView移除,這樣就模擬出了一個Dialog的效果~~ ,當(dāng)然這個Dialog的樣式,動畫就可以自己想怎么寫就怎么寫了撒
  4. 通過activity.getWindow().getDecorView()可以獲得DecorView

[下面大量 代碼 ]

第一個對話框的實現(xiàn)

public class TipsDialog {
  private Activity activity;
  private View rootView;
  private TextView confirmTextView;
  private TextView cancelTextView;
  private TextView contentTextView;

  private boolean isShowing;

  public TipsDialog(Activity activity) {
    this.activity = activity;
    isShowing = false;
    rootView = LayoutInflater.from(activity).inflate(R.layout.view_tips_dialog,null);
    confirmTextView = (TextView) rootView.findViewById(R.id.view_tips_dialog_tv_confirm);
    cancelTextView = (TextView) rootView.findViewById(R.id.view_tips_dialog_tv_cancel);
    contentTextView = (TextView) rootView.findViewById(R.id.view_tips_dialog_tv_content);

  }

  public void show(){
    if(activity == null){
      return;
    }
    if(isShowing){
      return;
    }
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    rootView.setLayoutParams(params);
    decorView.addView(rootView);
    rootView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        dismiss();
      }
    });

    RotateAnimation rotateAnimation = new RotateAnimation(0,720f,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f);
    rotateAnimation.setDuration(2000);
    contentTextView.startAnimation(rotateAnimation);

    isShowing = true;
  }

  public void dismiss(){
    if(!isShowing){
      return;
    }
    isShowing = false;
    if(rootView.getParent() == null){
      return;
    }
    ViewGroup parent = (ViewGroup) rootView.getParent();
    parent.removeView(rootView);

  }

  public int getRandomColor(){
    Random random = new Random();
    return Color.argb(random.nextInt(200),random.nextInt(240),random.nextInt(240),random.nextInt(240));
  }

  public boolean isShowing() {
    return isShowing;
  }
}

其實就是show的時候?qū)⒉季痔砑拥紻ecorView上面去,dismiss的時候?qū)⒉季謴腄ecorView上面移除

提示的實現(xiàn)(沒有處理完善~~ 僅僅就是說明哈DecorView)

public class TopTipDialog {
  private Activity activity;
  private View rootView;
  private boolean isShowing;
  private static final int VIEW_HEIGHT = 64;//px

  public TopTipDialog(Activity activity) {
    this.activity = activity;
    rootView = LayoutInflater.from(activity).inflate(R.layout.view_top_tip_dialog,null);
  }


  public void show(){

    if(isShowing){
      return;
    }
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, VIEW_HEIGHT);
    params.gravity = Gravity.TOP;
    params.setMargins(0,0,0,-VIEW_HEIGHT);
    rootView.setLayoutParams(params);

    TranslateAnimation translateAnimation = new TranslateAnimation(0,0,-VIEW_HEIGHT,0);
    translateAnimation.setDuration(1500);
    translateAnimation.setFillAfter(true);
    decorView.addView(rootView);
    rootView.startAnimation(translateAnimation);

    rootView.postDelayed(new Runnable() {
      @Override
      public void run() {
        TranslateAnimation translateAnimation1 = new TranslateAnimation(0,0,0,-VIEW_HEIGHT);
        translateAnimation1.setDuration(1500);
        translateAnimation1.setFillAfter(true);
        rootView.startAnimation(translateAnimation1);
      }
    },3000);

  }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android圖片選擇器 豐富的配置選項

    Android圖片選擇器 豐富的配置選項

    這篇文章主要介紹了Android圖片選擇器,豐富的配置選項,極大程度的簡化使用,感興趣的小伙伴們可以參考一下
    2016-08-08
  • 解決Android Studio sdk emulator directory is missing問題

    解決Android Studio sdk emulator directory is missing問題

    這篇文章主要介紹了解決Android Studio sdk emulator directory is missing問題,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Android編程開發(fā)之TextView文字顯示和修改方法(附TextView屬性介紹)

    Android編程開發(fā)之TextView文字顯示和修改方法(附TextView屬性介紹)

    這篇文章主要介紹了Android編程開發(fā)之TextView文字顯示和修改方法,結(jié)合實例詳細分析了Android中TextView控件關(guān)于文字的顯示及修改技巧,并附帶了TextView屬性介紹,需要的朋友可以參考下
    2015-12-12
  • Android檢測Activity或者Service是否運行的方法

    Android檢測Activity或者Service是否運行的方法

    下面小編就為大家分享一篇Android檢測Activity或者Service是否運行的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • Android 利用反射+try catch實現(xiàn)sdk按需引入依賴庫的方法

    Android 利用反射+try catch實現(xiàn)sdk按需引入依賴庫的方法

    這篇文章主要介紹了Android 利用反射+try catch來實現(xiàn)sdk按需引入依賴庫,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-11-11
  • Android日歷控件PickTime代碼實例

    Android日歷控件PickTime代碼實例

    這篇文章主要介紹了Android日歷控件PickTime代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-09-09
  • 快速調(diào)試Android應(yīng)用系統(tǒng)修改ro.debuggable屬性的兩種方式

    快速調(diào)試Android應(yīng)用系統(tǒng)修改ro.debuggable屬性的兩種方式

    這篇文章主要為大家介紹了快速調(diào)試Android應(yīng)用系統(tǒng)修改ro.debuggable屬性的兩種方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-10-10
  • Android Bitmap的截取及狀態(tài)欄的隱藏和顯示功能

    Android Bitmap的截取及狀態(tài)欄的隱藏和顯示功能

    Bitmap是Android系統(tǒng)中的圖像處理中最重要類之一。Bitmap可以獲取圖像文件信息,對圖像進行剪切、旋轉(zhuǎn)、縮放,壓縮等操作,并可以以指定格式保存圖像文件。這篇文章主要介紹了Android Bitmap的截取及狀態(tài)欄的隱藏和顯示功能,需要的朋友可以參考下
    2017-11-11
  • Android彈幕框架 黑暗火焰使基本使用方法

    Android彈幕框架 黑暗火焰使基本使用方法

    這篇文章主要介紹了Android彈幕框架黑暗火焰使基本使用方法,需要的朋友可以參考下。今天我將分享由BiliBili開源的Android彈幕框架(DanmakuFlameMaster)的學(xué)習(xí)經(jīng)驗,感興趣的朋友一起看看吧
    2016-10-10
  • Android實現(xiàn)仿今日頭條點贊動畫效果實例

    Android實現(xiàn)仿今日頭條點贊動畫效果實例

    我想看到今日頭條的點贊效果,應(yīng)該都覺得很絢麗吧,下面這篇文章主要給大家介紹了關(guān)于Android實現(xiàn)仿今日頭條點贊動畫效果的相關(guān)資料,文中通過示例代價介紹的非常詳細,需要的朋友可以參考下
    2022-02-02

最新評論