andorid popupwindow 更新時動畫的實現,可實現一個視窗被一個視窗推上去的效果

來源:互聯網
上載者:User

標籤:android   style   class   blog   c   code   

最近由於項目需要,一直在尋找一個快顯視窗,在另一個快顯視窗彈出時,推上去的效果,居然找不到,經過不懈的努力,終於實現了popupwindow在更新時的動畫。

先上代碼:

 1 import android.animation.ObjectAnimator; 2 import android.annotation.SuppressLint; 3 import android.content.Context; 4 import android.graphics.drawable.BitmapDrawable; 5 import android.util.AttributeSet; 6 import android.view.LayoutInflater; 7 import android.view.View; 8 import android.widget.PopupWindow; 9 import android.widget.TextView;10 11 public class NotePopWindow extends PopupWindow {12     private TextView mNodeTextView;13     private Context mContext;14     private ViewWrapper mWrapper;15 16     public NotePopWindow(Context context, int width, int height) {17         super(LayoutInflater.from(context).inflate(R.layout.fullscreen_view_note_popwindow, null), width, height);18         mContext = context;19         setBackgroundDrawable(new BitmapDrawable());20         setAnimationStyle(R.style.anim_note_bottombar);21         initViews();22     }23 24     public NotePopWindow(Context context) {25         super(context);26 27     }28 29     public NotePopWindow(Context context, AttributeSet attributeSet) {30         super(context, attributeSet);31     }32 33     private void initViews() {34         mNodeTextView = (TextView) getContentView().findViewById(R.id.note_view);35         mWrapper = new ViewWrapper(getContentView());36     }37 38     @SuppressLint("NewApi")39     public void startUpAnimation() {40         ObjectAnimator translationRight = ObjectAnimator.ofInt(mWrapper, "Y", (int) mContext.getResources()41                 .getDimension(R.dimen.bottom_menu_window_height));42         translationRight.setDuration(540);43         translationRight.start();44     }45 46     @SuppressLint("NewApi")47     public void startDownAnimation() {48         ObjectAnimator translationRight = ObjectAnimator.ofInt(mWrapper, "Y", 0);49         translationRight.setDuration(360);50         translationRight.start();51     }52 53     private class ViewWrapper {54         private View mTarget;55         private boolean isUp = true;56 57         public ViewWrapper(View target) {58             setmTarget(target);59         }60 61         @SuppressWarnings("unused")62         public int getY() {63             if (isUp) {64                 isUp = false;65                 return 0;66 67             } else {68                 isUp = true;69                 return (int) mContext.getResources().getDimension(R.dimen.bottom_menu_window_height);70             }71 72         }73 74         @SuppressWarnings("unused")75         public void setY(int height) {76             update(0, height, -1, -1);77         }78 79         @SuppressWarnings("unused")80         public View getmTarget() {81             return mTarget;82         }83 84         public void setmTarget(View mTarget) {85             this.mTarget = mTarget;86         }87     }88 }

實現原理其實就是依靠屬性動畫,但是屬性動畫只能作用於有set和get方法的屬性,所以關鍵就是寫一個封裝類,提供屬性的set和get方法,在set方法中調用popwindow的update方法,即可在update時實現動畫。

講的不是很清楚,代碼如上,如果實在看不懂可以郵件、qq聯絡。。。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.