样式:

  layout:

popup_appinfo.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/pop_bg"
android:orientation="horizontal" > <TextView
android:id="@+id/tv_uninstall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:drawablePadding="3dp"
android:drawableTop="@drawable/ic_uninstall"
android:text="卸载"
android:textColor="@color/black"
android:textSize="16sp" /> <TextView
android:id="@+id/tv_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:drawablePadding="3dp"
android:drawableTop="@drawable/ic_open"
android:text="打开"
android:textColor="@color/black"
android:textSize="16sp" /> <TextView
android:id="@+id/tv_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:drawablePadding="3dp"
android:drawableTop="@drawable/ic_share"
android:text="分享"
android:textColor="@color/black"
android:textSize="16sp" /> <TextView
android:id="@+id/tv_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:drawablePadding="3dp"
android:drawableTop="@drawable/ic_info"
android:text="信息"
android:textColor="@color/black"
android:textSize="16sp" /> </LinearLayout>

  anim:

popup_enter.xml

 <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" > <translate
android:duration="400"
android:fromXDelta="100%p"
android:interpolator="@android:interpolator/overshoot"
android:toXDelta="0" /> <alpha
android:duration="400"
android:fromAlpha="0.2"
android:toAlpha="1.0" /> </set>

popup_exit.xml

 <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" > <translate
android:duration="400"
android:fromXDelta="0"
android:interpolator="@android:interpolator/anticipate"
android:toXDelta="50%p" /> <alpha
android:duration="400"
android:fromAlpha="1.0"
android:toAlpha="0" /> </set>

code:

Activity.java

......

     //显示popupwindow
protected void showPopup(View itemView) {
if (mPopupWindow == null) {//只需要初始化一次弹窗
//初始化弹窗布局
View view = View.inflate(this, R.layout.popup_appinfo, null); //设置按钮点击事件
TextView tvUninstall = (TextView) view
.findViewById(R.id.tv_uninstall);
TextView tvOpen = (TextView) view.findViewById(R.id.tv_open);
TextView tvShare = (TextView) view.findViewById(R.id.tv_share);
TextView tvInfo = (TextView) view.findViewById(R.id.tv_info);
tvUninstall.setOnClickListener(this);
tvOpen.setOnClickListener(this);
tvShare.setOnClickListener(this);
tvInfo.setOnClickListener(this); //初始化弹窗对象
////参1:布局; 参2,3:宽高; 参4:获取焦点
mPopupWindow = new PopupWindow(view,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT, true); //设置背景;只有设置了背景,点击窗口外侧和返回键,弹窗才会消失
mPopupWindow.setBackgroundDrawable(new ColorDrawable()); //设置动画样式
mPopupWindow.setAnimationStyle(R.style.PopupAnim);
} //显示在item正下方, 然后向上偏移一个item的高度
mPopupWindow.showAsDropDown(itemView, 60, -itemView.getHeight());
}

......

//弹窗消失

mPopupWindow.dismiss();

......

popupwindow展示的更多相关文章

  1. android模仿58筛选下拉框(PopupWindow实现)

    前言:前几天用58同城APP找房子的时候,看到筛选下拉框蛮不错的,然后也有很多朋友需要实现这个功能,于是从网上下载了一个demo,在他的基础上进行修改,花了几个小时对他的代码进行修改,重构,封装.把一 ...

  2. PopupWindow 的常用api封装

    对PopupWindow常用API的简单封装,几行代码就搞定PopupWindow弹窗,使用Builder模式,链式调用,像使用AlertDialog 一样 封装通用PopupWindow,Custo ...

  3. Android仿qq聊天记录长按删除功能效果

    最近项目在做IM即时通讯开发,在删除聊天列表的时候跟删除聊天详细信息的时候,产品经理想要跟ios一样,在当前选中行上方弹出一个删除窗口.于是先从网上找demo,找了一个发现是Dialog做的,我感觉没 ...

  4. Android PopupWindow Dialog 关于 is your activity running 崩溃详解

    Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...

  5. Android PopupWindow怎么合理控制弹出位置(showAtLocation)

    说到PopupWindow,应该都会有种熟悉的感觉,使用起来也很简单 // 一个自定义的布局,作为显示的内容 Context context = null; // 真实环境中要赋值 int layou ...

  6. PopupWindow的使用

    如图是效果图     2种常用PopupWindow的使用 下载地址:http://download.csdn.net/detail/qq_29774291/9683258 第一个展示一个下拉的Lis ...

  7. Android项目实战(十七):QQ空间实现(二)—— 分享功能 / 弹出PopupWindow

    这是一张QQ空间说说详情的截图. 分析: .点击右上角三个点的图标,在界面底部弹出一个区域,这个区域有一些按钮提供给我们操作 .当该区域出现的时候,详情界面便灰了,也说成透明度变化了 .当任意选了一个 ...

  8. 使用PopupWindow

    PopupWindow可以用来实现弹出任意位置的菜单,比Context Menu和Option Menu灵活性更高.Android中弹出一个PopupWindow基本有两个方法: 1 2 //Disp ...

  9. Android - PopupWindow

    PopupWindow就是一个可以显示在当前界面上的浮动容器,它可以用来显示任意一个View,同时还可以指定显示的位置. 下面写一个显示下拉的例子: PopupWindow mpopupWindow; ...

随机推荐

  1. ASP.NET WebAPi之断点续传下载(下)

    前言 上一篇我们穿插了C#的内容,本篇我们继续来讲讲webapi中断点续传的其他情况以及利用webclient来实现断点续传,至此关于webapi断点续传下载以及上传内容都已经全部完结,一直嚷嚷着把S ...

  2. Android百度地图 关于visibility="gone"的奇葩问题

    最近在项目中遇到一个奇葩问题,花了很长时间,在这里记录下. 问题描述:我的主界面是ViewPager+Fragment,并且设置缓存了我的4个ViewPager页面.左侧是一个侧滑菜单,点击相应按钮打 ...

  3. html5 meta(移动端)介绍及使用

    随着高端手机(Andriod,Iphone,Ipod,WinPhone等)的盛行,移动互联应用开发也越来越受到人们的重视,用html5开发移动应用是最好的选择.然而,每一款手机有不同的分辨率,不同屏幕 ...

  4. js制作点击会自动隐藏的导航栏(固定在在头部的)

    想必大家应该见过这样的特效,本来头部是固定在网页的最上方的,点一下缩进去,再点一下 又可以缩回来,这种效果怎么实现的呢,我今天就做了一个.菜鸟勿喷. @charset "utf-8" ...

  5. TSQL查询45道题

    一.设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1- ...

  6. GUI 和 GUILayout 的区别

    GUI 和 GUILayout 的区别 A~ GUI是Unity中的基础控件类,其中包含了常用的GUI控件,列如Button,Label,PasswordField,slider,Window等等~ ...

  7. Net设计模式实例之原型模式( Prototype Pattern)

    一.原型模式简介(Brief Introduction) 原型模式(Prototype Pattern):用原型实例指定创建对象的种类,并通过拷贝这些原型创建新的对象. Specify the kin ...

  8. web.config配置

    <appSettings> <add key="DepartmentRootID" value="A90AEAEC-E3D4-43DE-BB67-854 ...

  9. asp.net开发的一些问题

    关于Ajax说法错误的是( ).(选择一项) MVC是一种流行的软件设计模式,它把系统分为三个模块.三个模块为( ). 在ASP.NET中,关于WebService的说法正确的是( ) .NET中Ob ...

  10. 使用SignalR实现即时通讯功能

    教程简介 SignalR的好处是可以让多个客户端之间进行互动,比如这篇教程就展示了当你在页面上拖动矩形方块的同时,其它打开这个页面的用户也将会看到你拖动的轨迹以及最终的结果,当然他们也可以通过拖动该方 ...