Android的PopWindow动画实现
转载博客:http://www.open-open.com/lib/view/open1423626956186.html
1.实现步骤
<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动画实现的更多相关文章
- Android立体旋转动画实现与封装(支持以X、Y、Z三个轴为轴心旋转)
本文主要介绍Android立体旋转动画,或者3D旋转,下图是我自己实现的一个界面 立体旋转分为以下三种: 1. 以X轴为轴心旋转 2. 以Y轴为轴心旋转 3. 以Z轴为轴心旋转--这种等价于andro ...
- Android中矢量动画
Android中矢量动画 Android中用<path> 标签来创建SVG,就好比控制着一支画笔,从一点到一点,动一条线. <path> 标签 支持一下属性 M = (Mx, ...
- Android Animation(动画)
前言 Android 平台提供实现动画的解决方案(三种) 一.3.0以前,android支持两种动画: (1)Frame Animation:顺序播放事先做好的图像,与gif图片原理类似,是一种逐帧动 ...
- android 补间动画和Animation
介绍: 补间动画是一种设定动画开始状态.结束状态,其中间的变化由系统计算补充.这也是他叫做补间动画的原因. 补间动画由Animation类来实现具体效果,包括平移(TranslateAnimation ...
- Android中过场动画
overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left); 第一参数为进入的动画 第二参数为退出的动画 进入的动画 ...
- Android 自定义波浪动画 --"让进度浪起来~"
原文链接:http://www.jianshu.com/p/0e25a10cb9f5 一款效果不错的动画,实现也挺简单的,推荐阅读学习~ -- 由 傻小孩b 分享 waveview <Andro ...
- Android 三种动画详解
[工匠若水 http://blog.csdn.net/yanbober 转载请注明出处.点我开始Android技术交流] 1 背景 不能只分析源码呀,分析的同时也要整理归纳基础知识,刚好有人微博私信让 ...
- Android自定义窗口动画
第一步,设置出现和消失的xml 1.在res/anim下创建enter_anim.xml,设置窗口出现的动画 <?xml version="1.0" encoding=&qu ...
- 实例源码--Android自定义Gallery动画效果
相关文档与源码: 下载源码 技术要点: 1.自定义控件的使用 2.Gallery控件的使用实例 3.详细的源码注释 ...... 详细介绍: 1.自定义控件的使用 本套源码通过自定义控件的方式,继 ...
随机推荐
- phantomjs 双向认证,访问nginx,https
应用背景: phantomjs的一个爬虫,访问https站点,单向认证(只认证服务器身份)的都可以,双向认证(服务器和客户端都需要认证)必须上传本地证书: 开始用一个包含公钥私钥的PEM证书访问,怎么 ...
- iOS判断是模拟器还是真机
#if TARGET_IPHONE_SIMULATOR //模拟器 #elif TARGET_OS_IPHONE //真机 #endif
- Convert PLY to VTK Using PCL 1.6.0 使用PCL库将PLY格式转为VTK格式
PLY格式是比较流行的保存点云Point Cloud的格式,可以用MeshLab等软件打开,而VTK是医学图像处理中比较常用的格式,可以使用VTK库和ITK库进行更加复杂的运算处理.我们可以使用Par ...
- LabVIEW 吸星大法 - 看见的好东西都是我的(下篇)
前言 写了多年的LabVIEW程序,你是否面临这样的问题 总是在做一些重复的工作,感觉很没有意思: 总在不停的写代码,做类似的控件,实现相同的功能,丝毫没有成就感: 总在天加班,没有时间去提高自己; ...
- spring hibernate4 c3p0连接池配置
c3p0-0.9.1.2.jar,c3p0-oracle-thin-extras-0.9.1.2.jar,点此下载 <bean id="dataSource" class=& ...
- express-session 保存遇到的问题
今天在用express4 试着做网站的时候,发现request.session 中一直不能保存新的值,还一直报一个错 express-session deprecated undefined resa ...
- tar 命令
tar -cf 打包的文件名 打包的文件 ------tar -cf db.all test.txt (-c 表示建立新的包,-f通常是必选项) tar -tf 打包 ...
- python serial 获取所有的串口名称
http://blog.csdn.net/qq61394323/article/details/44619511 #!/usr/bin/env python # -*- coding: utf-8 - ...
- ORACLE冷备份与恢复
ORACLE备份和恢复有三种方式: (1)数据泵(expdp/impdp) (2)冷备份 (3)RMAN备份 就分类而言,(1)和(2)统有称为"冷"备份,(3)称为"热 ...
- ASP.NET Identity V2
Microsoft.AspNet.Identity是微软在MVC 5.0中新引入的一种membership框架,和之前ASP.NET传统的membership以及WebPage所带来的SimpleMe ...