转载博客:http://www.open-open.com/lib/view/open1423626956186.html

1.实现步骤

1.主布局activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" > <Button
android:id="@+id/open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="打开泡泡窗口" /> </RelativeLayout>

2.popupwindow.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <GridView
android:id="@+id/gv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00bfff"
android:numColumns="" >
</GridView> </LinearLayout>

3.MainActivity

public class MainActivity extends Activity implements OnClickListener {

    private Button open;
private View parent;
private View popView;
private PopupWindow popupWindow;
private GridView gv; private String[] names = { "生", "如", "夏", "花", "海", "阔", "天", "空" };
private int[] images = { R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher }; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
parent = findViewById(R.id.main);
open = (Button) findViewById(R.id.open);
open.setOnClickListener(this);
initPopupWindow();
} /**
* 初始化popupWindow
*/
private void initPopupWindow() {
popView = getLayoutInflater().inflate(R.layout.popupwindow, null);
popupWindow = new PopupWindow(popView,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
gv = (GridView) popView.findViewById(R.id.gv);
gv.setAdapter(MyAdapter()); } /**
* 为GridView填充数据
*
* @return
*/
private ListAdapter MyAdapter() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for (int i = ; i < names.length; i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("names", names[i]);
map.put("images", images[i]);
list.add(map);
}
SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
R.layout.pop_item, new String[] { "names", "images" },
new int[] { R.id.tv, R.id.img });
return simpleAdapter;
} @Override
public void onClick(View v) {
//为popWindow添加动画效果
popupWindow.setAnimationStyle(R.style.popWindow_animation);
// 点击弹出泡泡窗口
popupWindow.showAtLocation(parent, Gravity.BOTTOM, , );
}
}

4.为了实现动画进出效果,定义两个布局文件

popupwindow_enter.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <translate
android:duration=""
android:fromYDelta="100%p"
android:toYDelta="" /> <alpha
android:duration=""
android:fromAlpha="0.5"
android:toAlpha="1.0" /> </set>

popupwindow_exit.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha
android:duration=""
android:fromAlpha="1.0"
android:toAlpha="0.5" /> <translate
android:fromYDelta=""
android:toYDelta="100%p"
android:duration="" /> </set>

5.style.xml

<style name="popWindow_animation">
<item name="android:windowEnterAnimation">@anim/popupwindow_enter</item>
<item name="android:windowExitAnimation">@anim/popupwindow_exit</item>
</style>

 PopuWindow和软键盘共存时的设置

一、键盘不消失,popuwindow在下层布局大小不变

  

popupWindow=new PopupWindow(popuview,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// 需要设置一下此参数,点击外边可消失
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//设置点击窗口外边窗口消失
popupWindow.setOutsideTouchable(true);
//设置弹出窗体需要软键盘,
popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
//再设置模式,和Activity的一样,覆盖。
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

二、键盘不消失,popuWindow在下层,布局上移

  

popupWindow=new PopupWindow(popuview,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// 需要设置一下此参数,点击外边可消失
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//设置点击窗口外边窗口消失
popupWindow.setOutsideTouchable(true); //设置弹出窗体需要软键盘,
popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
//再设置模式,和Activity的一样,覆盖,调整大小。
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

三、键盘消失

  

popupWindow=new PopupWindow(popuview,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// 需要设置一下此参数,点击外边可消失
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//设置点击窗口外边窗口消失
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);

Android的PopWindow动画实现的更多相关文章

  1. Android立体旋转动画实现与封装(支持以X、Y、Z三个轴为轴心旋转)

    本文主要介绍Android立体旋转动画,或者3D旋转,下图是我自己实现的一个界面 立体旋转分为以下三种: 1. 以X轴为轴心旋转 2. 以Y轴为轴心旋转 3. 以Z轴为轴心旋转--这种等价于andro ...

  2. Android中矢量动画

    Android中矢量动画 Android中用<path> 标签来创建SVG,就好比控制着一支画笔,从一点到一点,动一条线. <path> 标签 支持一下属性 M = (Mx, ...

  3. Android Animation(动画)

    前言 Android 平台提供实现动画的解决方案(三种) 一.3.0以前,android支持两种动画: (1)Frame Animation:顺序播放事先做好的图像,与gif图片原理类似,是一种逐帧动 ...

  4. android 补间动画和Animation

    介绍: 补间动画是一种设定动画开始状态.结束状态,其中间的变化由系统计算补充.这也是他叫做补间动画的原因. 补间动画由Animation类来实现具体效果,包括平移(TranslateAnimation ...

  5. Android中过场动画

    overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left); 第一参数为进入的动画 第二参数为退出的动画 进入的动画 ...

  6. Android 自定义波浪动画 --"让进度浪起来~"

    原文链接:http://www.jianshu.com/p/0e25a10cb9f5 一款效果不错的动画,实现也挺简单的,推荐阅读学习~ -- 由 傻小孩b 分享 waveview <Andro ...

  7. Android 三种动画详解

    [工匠若水 http://blog.csdn.net/yanbober 转载请注明出处.点我开始Android技术交流] 1 背景 不能只分析源码呀,分析的同时也要整理归纳基础知识,刚好有人微博私信让 ...

  8. Android自定义窗口动画

    第一步,设置出现和消失的xml 1.在res/anim下创建enter_anim.xml,设置窗口出现的动画 <?xml version="1.0" encoding=&qu ...

  9. 实例源码--Android自定义Gallery动画效果

    相关文档与源码: 下载源码   技术要点: 1.自定义控件的使用 2.Gallery控件的使用实例 3.详细的源码注释 ...... 详细介绍: 1.自定义控件的使用 本套源码通过自定义控件的方式,继 ...

随机推荐

  1. TortoiseSVN 合并操作简明教程

    下列步骤展示了如何将分支A中的修改合并到分支B. 1.在分支B的本地副本目录中选择"合并(Merge)". 2.选择“合并一个版本范围(Merge a range of revis ...

  2. Oozie_初识

    Oozie 任务调度框架(基于工作流) oozie运行于hadoop集群,对hive,mr,flume,Soop,spark,shell等框架进行任务流调度 如: job1-->job2 &am ...

  3. mongodb的用户管理及安全认证

    1.确认mongodb的版本 > use admin switched to db admin > db.runCommand({}) { "version" : &q ...

  4. C# winform treeView checkbox全选反选

    private void treeView2_AfterCheck(object sender, TreeViewEventArgs e)        {            if (e.Acti ...

  5. GIT的认识

    说实话,在听到小伙伴们都说赶紧做作业的时候很茫然,连一点头绪都没有,根本不知道从何入手,但不能因为不会就不去做,于是还是拿起手机,找到小伙伴商量着做着,虽然等的过程很焦急,但还是注册成功了.而开始写对 ...

  6. iOS 开发快速导引:TableView 和 CoreData【草】

    所有列表式的数据都是用 TableView 显示的 预览 待补充 原料 NSFetchedResultsController 用来操作 NSFetchRequst,有执行查询,监听变化,数据缓存等功能 ...

  7. SQL Server 2008, 2008 R2, 2012 and 2014 完全支持TLS1.2加密传输

    SQL Server 2008, 2008 R2, 2012 and 2014 完全支持TLS1.2加密传输 微软高兴地宣布所有主流SQL Server客户端驱动和SQL Server发行版已经支持T ...

  8. 安卓动态调试七种武器之离别钩 – Hooking(上)

    安卓动态调试七种武器之离别钩 – Hooking(上) 作者:蒸米@阿里聚安全 0x00 序 随着移动安全越来越火,各种调试工具也都层出不穷,但因为环境和需求的不同,并没有工具是万能的.另外工具是死的 ...

  9. 剑指Offer面试题:20.栈的压入、弹出序列

    一.题目:栈的压入.弹出序列 题目:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1.2.3.4.5是某栈的压栈序列,序列4 ...

  10. ASP.Net MVC开发基础学习笔记:三、Razor视图引擎、控制器与路由机制学习

    一.天降神器“剃须刀” — Razor视图引擎 1.1 千呼万唤始出来的MVC3.0 在MVC3.0版本的时候,微软终于引入了第二种模板引擎:Razor.在这之前,我们一直在使用WebForm时代沿留 ...