The implementation of the animation when the andorid popupwindow is updated allows a window to be pushed up by a window.

Source: Internet
Author: User

Recently, due to project requirements, I have been searching for a pop-up window. When another pop-up window pops up, I cannot find the push effect. After unremitting efforts, finally, the animation of the popupwindow is implemented when it is updated.

First run the Code:

 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 }

The implementation principle is actually to rely on Attribute animation, but attribute animation can only act on attributes with the set and get methods. The key is to write a packaging class and provide the set and get methods of attributes, call the update method of popwindow in the set method to implement animation during update.

I am not very clear about it. The Code is as above. If you cannot understand it, you can contact me via email or qq...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.