Android divides windows into multiple levels. To achieve the desktop lyrics, you only need to set the level of the Window to the level of the desktop Window, and also have the floating Window effect that can be freely moved. Let's take a look at the Code:
Package com. orgcent. desktop;
Import android. app. Application;
Import android. content. Context;
Import android. view. LayoutInflater;
Import android. view. MotionEvent;
Import android. view. View;
Import android. view. WindowManager;
Import android. view. View. OnTouchListener;
Public class BaseAppliction extends Application {
WindowManager mWM;
WindowManager. LayoutParams mWMParams;
@ Override
Public void onCreate (){
MWM = (WindowManager) getSystemService (Context. WINDOW_SERVICE );
Final View win = LayoutInflater. from (this). inflate (R. layout. ctrl_window, null );
Win. setOnTouchListener (new OnTouchListener (){
Float lastX, lastY;
Public boolean onTouch (View v, MotionEvent event ){
Final int action = event. getAction ();
Float x = event. getX ();
Float y = event. getY ();
If (action = MotionEvent. ACTION_DOWN ){
LastX = x;
LastY = y;
} Else if (action = MotionEvent. ACTION_MOVE ){
MWMParams. x + = (int) (x-lastX );
MWMParams. y + = (int) (y-lastY );
MWM. updateViewLayout (win, mWMParams );
}
Return true;
}
});
WindowManager wm = mWM;
WindowManager. LayoutParams wmParams = new WindowManager. LayoutParams ();
MWMParams = wmParams;
WmParams. type = 2002; // type is the key. Here, 2002 indicates the system-level window. You can also try 2003.
WmParams. format = 1;
WmParams. flags = 40;
WmParams. width = 300;
WmParams. height = 200;
Wm. addView (win, wmParams );
}
}
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: background = "# ffffff"
Android: orientation = "vertical"
Android: padding = "5dp">
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center"
Android: textColor = "#000000" android: text = "I love to add both sides immediately blocked hot and sour fans inspired the http://orgcent.com"/>
</LinearLayout>
Demo: http://code.google.com/p/android-custom-view/downloads/list
From the blog of radish Cabbage