博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PopupWindow使用
阅读量:3984 次
发布时间:2019-05-24

本文共 1744 字,大约阅读时间需要 5 分钟。

使用步骤:

1.创建PopupWindow的xml布局

2.使用布局创建PopupWindow

3.设置PopupWindow属性并显示

效果图:

示例代码:

java代码
list_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {            public void onItemClick(AdapterView
parent, View view, int position, long id) {//获得布局View contentView = View.inflate(AppManagerActivity.this, R.layout.popup_item, null);//获得PopupWindow中的控件LinearLayout ll_1 = (LinearLayout) contentView.findViewById(R.id.ll_1);LinearLayout ll_2 = (LinearLayout) contentView.findViewById(R.id.ll_2);LinearLayout ll_3 = (LinearLayout) contentView.findViewById(R.id.ll_3);LinearLayout ll_4 = (LinearLayout) contentView.findViewById(R.id.ll_4);//为控件设置点击事件ll_1.setOnClickListener(AppManagerActivity.this);ll_2.setOnClickListener(AppManagerActivity.this);ll_3.setOnClickListener(AppManagerActivity.this);ll_4.setOnClickListener(AppManagerActivity.this);//-2表示包裹内容 是长和宽popupWindow = new PopupWindow(contentView, -2, -2);//注意:给popupWindow一张透明的图片(这样动画效果才生效)popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//定义需要放置x和yint[] i = new int[2];//获取到Window里面的位置view.getLocationInWindow(i);//由于我们这块需要取y轴的值所以取1popupWindow.showAtLocation(parent, Gravity.TOP + Gravity.LEFT, 80, i[1]);//Animation.RELATIVE_TO_SELF相对自己ScaleAnimation scaleAnimation = new ScaleAnimation(0.5f, 1.0f, 0.5f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);scaleAnimation.setDuration(500);//从半透明开始到不透明AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 1.0f);alphaAnimation.setDuration(500);//动画集合AnimationSet animationSet = new AnimationSet(false);animationSet.addAnimation(alphaAnimation);animationSet.addAnimation(scaleAnimation);//启动动画contentView.startAnimation(animationSet);}
//关闭PopupWindow
popupWindow.dismiss();
布局文件
你可能感兴趣的文章
Go学习(7):函数
查看>>
Go学习(8):指针
查看>>
Go学习(9):结构体
查看>>
Go学习(10):方法
查看>>
Go学习(11):接口
查看>>
Go学习(12):面向对象
查看>>
Go学习(13):异常
查看>>
Go学习(14):defer
查看>>
Go学习(15):并发与包
查看>>
Go学习(16):网络编程
查看>>
深入浅出区块链笔记
查看>>
Oracle学习(一)
查看>>
Oracle学习(二)
查看>>
[Spring Boot]Spring Boot Configuration Annotation Processor not found in classpath
查看>>
SpringBoot简单整合Swagger2
查看>>
websocket教程(一) 非常有趣的理解websocket
查看>>
spring事件机制
查看>>
Maven错误:was cached in the local repository, resolution will not be reattempted until the update
查看>>
Excel2013每次打开都提示重新安装/正在配置
查看>>
Oracle:ORA-00911: 无效字符
查看>>