博客
关于我
安卓使用window manager往屏幕上添加一个view
阅读量:341 次
发布时间:2019-03-04

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

如何往屏幕中任意位置添加一个view。

直接上代码

一、获取window manager

WindowManager windowManager = getWindowManager();

二、实例化你要添加的控件

ImageView imageView = new ImageView(context);

三、设置layoutparams,注意这里要用到WindowManager.LayoutParams

WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();layoutParams.format = PixelFormat.RGBA_8888;layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;layoutParams.width = 30;layoutParams.height = 30;layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;layoutParams.x = 30;layoutParams.y = 40;

在这里可以具体设置视图所添加到的位置

四、将view 和 布局参数add进window

windowManager.addview(imageView ,layoutParams);

END

转载地址:http://xepe.baihongyu.com/

你可能感兴趣的文章
mysql 字段类型类型
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
mysql 存在update不存在insert
查看>>
MySQL 数据库备份种类以及常用备份工具汇总
查看>>
mysql 更新子表_mysql 在update中实现子查询的方式
查看>>
MySQL 有什么优点?
查看>>
MySql 查询以逗号分隔的字符串的方法(正则)
查看>>
mysql 添加索引
查看>>
mysql 网络目录_联机目录数据库
查看>>
MySQL 聚簇索引&&二级索引&&辅助索引
查看>>
Mysql 脏页 脏读 脏数据
查看>>
mysql 自增id和UUID做主键性能分析,及最优方案
查看>>
Mysql 自定义函数
查看>>
mysql 行转列 列转行
查看>>
Mysql 表分区
查看>>
mysql 表的操作
查看>>
MySQL 触发器
查看>>
mysql 让所有IP访问数据库
查看>>
mysql 记录的增删改查
查看>>