码迷,mamicode.com
首页 > Windows程序 > 详细

popupwindow展示

时间:2016-04-05 00:32:44      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

  样式:

技术分享

 

  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="卸载"
16         android:textColor="@color/black"
17         android:textSize="16sp" />
18 
19     <TextView
20         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="打开"
27         android:textColor="@color/black"
28         android:textSize="16sp" />
29 
30     <TextView
31         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="分享"
38         android:textColor="@color/black"
39         android:textSize="16sp" />
40 
41     <TextView
42         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="信息"
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     <alpha
12         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     <alpha
12         android:duration="400"
13         android:fromAlpha="1.0"
14         android:toAlpha="0" />
15 
16 </set>

 

code:

Activity.java

......

 1     //显示popupwindow
 2     protected void showPopup(View itemView) {
 3         if (mPopupWindow == null) {//只需要初始化一次弹窗
 4             //初始化弹窗布局
 5             View view = View.inflate(this, R.layout.popup_appinfo, null);
 6 
 7             //设置按钮点击事件
 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             //初始化弹窗对象
19             ////参1:布局; 参2,3:宽高; 参4:获取焦点
20             mPopupWindow = new PopupWindow(view,
21                     WindowManager.LayoutParams.WRAP_CONTENT,
22                     WindowManager.LayoutParams.WRAP_CONTENT, true);
23 
24             //设置背景;只有设置了背景,点击窗口外侧和返回键,弹窗才会消失
25             mPopupWindow.setBackgroundDrawable(new ColorDrawable());
26 
27             //设置动画样式
28             mPopupWindow.setAnimationStyle(R.style.PopupAnim);
29         }
30 
31         //显示在item正下方, 然后向上偏移一个item的高度
32         mPopupWindow.showAsDropDown(itemView, 60, -itemView.getHeight());
33     }

 

......

  1 //弹窗消失

 2 mPopupWindow.dismiss(); 

......

 

popupwindow展示

标签:

原文地址:http://www.cnblogs.com/rongsnow/p/5353439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!