Popupwindow display, popupwindow

Source: Internet
Author: User

Popupwindow display, popupwindow

Style:

 

Layout:

Popup_appinfo.xml

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 3 android: layout_width = "wrap_content" 4 android: layout_height = "wrap_content" 5 android: background = "@ drawable/pop_bg" 6 android: orientation = "horizontal"> 7 8 <TextView 9 android: id = "@ + id/TV _uninstall" 10 android: layout_width = "wrap_content" 11 android: layout_height = "wrap_content" 12 android: layout_margin = "3dp" 13 android: drawablePadding = "3dp" 14 android: drawableTop = "@ drawable/ic_uninstall" 15 android: text = "Uninstall" 16 android: textColor = "@ color/black" 17 android: textSize = "16sp"/> 18 19 <TextView20 android: id = "@ + id/TV _open" 21 android: layout_width = "wrap_content" 22 android: layout_height = "wrap_content" 23 android: layout_margin = "3dp" 24 android: drawablePadding = "3dp" 25 android: drawableTop = "@ drawable/ic_open" 26 android: text = "open" 27 android: textColor = "@ color/black" 28 android: textSize = "16sp"/> 29 30 <TextView31 android: id = "@ + id/TV _share" 32 android: layout_width = "wrap_content" 33 android: layout_height = "wrap_content" 34 android: layout_margin = "3dp" 35 android: drawablePadding = "3dp" 36 android: drawableTop = "@ drawable/ic_share" 37 android: text = "share" 38 android: textColor = "@ color/black" 39 android: textSize = "16sp"/> 40 41 <TextView42 android: id = "@ + id/TV _info" 43 android: layout_width = "wrap_content" 44 android: layout_height = "wrap_content" 45 android: layout_margin = "3dp" 46 android: drawablePadding = "3dp" 47 android: drawableTop = "@ drawable/ic_info" 48 android: text = "info" 49 android: textColor = "@ color/black" 50 android: textSize = "16sp"/> 51 52 </LinearLayout>

 

Anim:

Popup_enter.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3     android:shareInterpolator="false" > 4  5     <translate 6         android:duration="400" 7         android:fromXDelta="100%p" 8         android:interpolator="@android:interpolator/overshoot" 9         android:toXDelta="0" />10 11     <alpha12         android:duration="400"13         android:fromAlpha="0.2"14         android:toAlpha="1.0" />15 16 </set>

 

Popup_exit.xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3     android:shareInterpolator="false" > 4  5     <translate 6         android:duration="400" 7         android:fromXDelta="0" 8         android:interpolator="@android:interpolator/anticipate" 9         android:toXDelta="50%p" />10 11     <alpha12         android:duration="400"13         android:fromAlpha="1.0"14         android:toAlpha="0" />15 16 </set>

 

Code:

Activity. java

......

1 // display popupwindow 2 protected void showPopup (View itemView) {3 if (mPopupWindow = null) {// you only need to initialize the pop-up window once. 4 // initialize the pop-up window layout. 5 View = view. inflate (this, R. layout. popup_appinfo, null); 6 7 // click event 8 TextView tvUninstall = (TextView) view 9. findViewById (R. id. TV _uninstall); 10 TextView tvOpen = (TextView) view. findViewById (R. id. TV _open); 11 TextView tvShare = (TextView) view. findViewById (R. id. TV _share); 12 TextView tvInfo = (TextView) view. findViewById (R. id. TV _info); 13 tvUninstall. setOnClickListener (this); 14 tvOpen. setOnClickListener (this); 15 tvShare. setOnClickListener (this); 16 tvInfo. setOnClickListener (this); 17 18 // initialize the pop-up window Object 19 // parameter 1: layout; parameter 2, 3: width and height; parameter 4: obtain focus 20 mPopupWindow = new PopupWindow (view, 21 WindowManager. layoutParams. WRAP_CONTENT, 22 WindowManager. layoutParams. WRAP_CONTENT, true); 23 24 // set the background; only when the background is set, click the outside of the window and return key, the pop-up window will disappear 25 mPopupWindow. setBackgroundDrawable (new ColorDrawable (); 26 27 // set the animation style 28 mPopupWindow. setAnimationStyle (R. style. popupAnim); 29} 30 31 // display at the bottom of the item, and then offset the height of an item to 32 mPopupWindow. showAsDropDown (itemView, 60,-itemView. getHeight (); 33}

 

......

1 // the pop-up window disappears

2 mPopupWindow. dismiss ();

......

 

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.