怎么中Android中自定义一个悬浮窗控件

  介绍

今天就跟大家聊聊有关怎么中Android中自定义一个悬浮窗控件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

<强>第一步设计类似烤面包的类FloatWindow

package  com.floatwindowtest.john.floatwindowtest.wiget;,   ,   import  android.app.Activity,   import  android.content.Context,   import  android.graphics.PixelFormat,   import  android.view.Gravity,   import  android.view.KeyEvent,   import  android.view.MotionEvent,   import  android.view.View,   import  android.view.ViewGroup,   import  android.view.WindowManager,   import  android.widget.FrameLayout,   import  android.widget.LinearLayout,   ,   import  static  android.view.ViewGroup.LayoutParams.MATCH_PARENT;,   import  static  android.view.ViewGroup.LayoutParams.WRAP_CONTENT;,   import  static  android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;,   import  static  android.view.WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;,   ,/* *,   ,* Created  by  john 提醒2017/3/10又是;   ,*/{class  FloatWindow    ,private  final  Context  mContext,   ,private  WindowManager  windowManager;   ,private  View  floatView;   ,private  WindowManager.LayoutParams 参数;   ,   ,public  FloatWindow (Context  mContext), {,   时间=this.mContext 才能;mContext;,   this.params 才能=,new  WindowManager.LayoutParams (),,   }大敌;   ,   ,/* *大敌;   *,才能显示浮动窗口,   *,才能@param  view    *,才能@param  x 视图距离左上角的x距离,   *,才能@param  y 视图距离左上角的y距离,   */才能,   ,void 显示(视图,View  int  x,, int  y), {,   this.windowManager 才能=,(WindowManager), this.mContext.getSystemService (Context.WINDOW_SERVICE);,   时间=params.height 才能;WindowManager.LayoutParams.WRAP_CONTENT;,   时间=params.width 才能;WindowManager.LayoutParams.WRAP_CONTENT;,   时间=params.gravity 才能;Gravity.TOP  |, Gravity.LEFT;,   时间=params.format 才能;PixelFormat.TRANSLUCENT;,   params.x 才能=,x,,   params.y 才能=,y,,   时间=params.type 才能;WindowManager.LayoutParams.TYPE_TOAST;,   时间=params.flags 才能;WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON  |, FLAG_NOT_FOCUSABLE  |, FLAG_WATCH_OUTSIDE_TOUCH    ,,,|,WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;,   floatView 才能=,,,   windowManager.addView才能(floatView, params);,   }大敌;   ,/* *大敌;   *,才能显示浮动窗口,   *,才能@param  view    *,才能@param  x    *,才能@param  y    *,才能@param  listener 窗体之外的监听,   *,才能@param  backListener 返回键盘监听,   */才能,   ,   ,void 显示(视图,View  int  x,, int  y, OutsideTouchListener 侦听器,,KeyBackListener  backListener), {,   this.windowManager 才能=,(WindowManager), this.mContext.getSystemService (Context.WINDOW_SERVICE);,   final 才能FloatWindowContainerView  containerView =, new  FloatWindowContainerView (this.mContext,侦听器,,backListener),,   containerView.addView才能(WRAP_CONTENT,看来,还以为;WRAP_CONTENT),,   时间=params.height 才能;WindowManager.LayoutParams.WRAP_CONTENT;,   时间=params.width 才能;WindowManager.LayoutParams.WRAP_CONTENT;,   时间=params.gravity 才能;Gravity.TOP  |, Gravity.LEFT;,   时间=params.format 才能;PixelFormat.TRANSLUCENT;,   params.x 才能=,x,,   params.y 才能=,y,,   时间=params.type 才能;WindowManager.LayoutParams.TYPE_TOAST;,//,//,,params.flags =, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON //,,,,|,WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM  |, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH //,,,,|,WindowManager.LayoutParams只FLAG_NOT_FOCUSABLE ,,   ,   时间=params.flags 才能;WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON    ,,,|,WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM  |, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH    ,,,|,WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;,   ,   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么中Android中自定义一个悬浮窗控件