因项目需求,要在界面显示悬浮摇杆,实现悬浮摇杆的操作如下:
1.获取窗口管理WindowManger
WindowManager windowManager=(WindowManager)getApplication().getSystemService(Context.WINDOW_SERVICE);
2.获取能够设置窗口的Param
WindowManager.LayoutParams params=new WindowManager.LayoutParams();
3.获取要加载进来的布局
LayoutInflater inflater=LayoutInflater.from(getApplication());
RelativeLayout relativeLayout = (RelativeLayout) inflater.inflate(R.layout.layout_rocker,null);
4.设置悬浮窗口的宽高(可以根据自己的情况,任意设定,int型的数据均可)
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
5.设置悬浮窗口开始加载进来的位置