转载博客: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. haha2

    # YOU - fhasd - fdks jf > jd sfkjd sf ```python print "helloworld" ``` 来自为知笔记(Wiz)

  2. 【DP】HDU 1260

    HDU 1260 Tickets 题意:有N个人要买票,你可以一个一个人卖票,时间分别为Xs,也可以相邻两个人一起卖票,时间为Ys,从早上八点开始卖票,问你何时最早将N个人的票卖完. 思路:解决情况是 ...

  3. BZOJ4262: Sum

    Description   Input 第一行一个数 t,表示询问组数. 第一行一个数 t,表示询问组数. 接下来 t 行,每行四个数 l_1, r_1, l_2, r_2.   Output 一共 ...

  4. browser-sync

    引入 大家写网页的时候,肯定都遇到这种情况,每次用sublime写完都要返回浏览器,刷新页面,而这个工具正好解决了这个问题,提高前端开发效率,这是一个npm的包 browser-sync browse ...

  5. db2循环

    db2普通循环结构 while循环 while 条件 do 循环体 end while; LOOP循环 SET V_INDEX = 0; AUTHLOOP: LOOP V_INDEXV_INDEX = ...

  6. windows service 1053错误 启动失败

    做项目移植的时候发现一个项目的window service启动失败,最后试出来是启动时间超时 解决办法是给window service设置一个长一点的等待时间,步骤如下: 启动,输入regedit启动 ...

  7. Javascript的自执行函数

    自执行函数其实也就是"立即执行的函数",它有四个特点:提高性能.利于压缩.避免冲突.依赖加载: 1.减少作用域查找 JS代码: // Anonymous function that ...

  8. 纯CCS绘制三角形箭头图案

    用CSS绘制三角形箭头.使用纯CSS,你只需要很少的代码就可以创作出各种浏览器都兼容的三角形箭头! CSS代码: /* create an arrow that points up */ div.ar ...

  9. 误删/usr文件夹解决办法

    http://blog.chinaunix.net/uid-2623904-id-3044156.html http://www.centoscn.com/CentOS/Intermediate/20 ...

  10. Python3.5+selenium操作Chrome浏览器

    1.安装selenium 命令提示符下输入: pip install selenium 2.下载chromedriver 点击下载 3.将解压后的chromedriver.exe放到chrome浏览器 ...