博客
关于我
安卓使用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万字总结!超详细!
查看>>
Mysql下载以及安装(新手入门,超详细)
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中null和空字符串的区别与问题!
查看>>
Mysql中varchar类型数字排序不对踩坑记录
查看>>
Mysql中存储引擎简介、修改、查询、选择
查看>>
mysql中实现rownum,对结果进行排序
查看>>
mysql中对于数据库的基本操作
查看>>
mysql中的 +号 和 CONCAT(str1,str2,...)
查看>>
MySQL中的count函数
查看>>
MySQL中的DB、DBMS、SQL
查看>>
MySQL中的DECIMAL类型:MYSQL_TYPE_DECIMAL与MYSQL_TYPE_NEWDECIMAL详解
查看>>
MySQL中的GROUP_CONCAT()函数详解与实战应用
查看>>