Android desktop lyrics (similar to TTPlayer)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.