PopupWindow implements pulling the menu bar like iOS QQ music (supports gestures and click operations)

Source: Internet
Author: User
Tags gety

PopupWindow implements pulling the menu bar like iOS QQ music (supports gestures and click operations)
If you are an expert, you can ignore N2. The source code is at the bottom.

This morning, a friend from the Andorid group asked me some questions about PopupWindow. I noticed a menu bar of QQ music last night, so let's proceed with that implementation today (You know)

First up and down the source image:

Paste our results (except for not looking like it, hahaha ):

Function implementation:

1: Bottom PopupWindow Rendering

2: gesture action control

3: button operation control

4: Click events inside the control

How to do?

Analysis:

First, this is a standard bottom PopupWindow. pop (which is abbreviated later) has two internal rows, each with a series of buttons,
Each button has its click event. pop supports gesture display or hiding. This series is what we need to do. Let's look at the code with our needs.

Package Structure:

This is not like before. I wrote a Demo and exported a bunch of packages. This time I used the Log Library:

Gradle:

 compile 'com.apkfuns.logutils:library:1.0.6'

One implementation classpublic class HomeActivity extends Root implements View.OnClickListener, View.OnTouchListener

There are a lot of findID In the example, in fact, you can use annotations to do these things, you can refer to the http://blog.csdn.net/ddwhan0123/article/details/47399259

OnClickListener solves all of our click events, from the button to the small icon in pop

OnTouchListener can be used to hide/display pop operations.

How to hide/display sliding data:
MoveY is a sliding distance judgment value. You can decide multiple scenarios.
MotionEvent. ACTION_DOWN records a coordinate when you touch the screen.
MotionEvent. ACTION_UP coordinates when the finger leaves, then?

The result is displayed after addition, subtraction, and subtraction. Is it So easy?

@ Override public boolean onTouch (View v, MotionEvent event) {switch (event. getAction () {case MotionEvent. ACTION_DOWN: y = event. getY (); LogUtils. d ("---> HomeActivity onTouch y = event. getY () "+ y); break; case MotionEvent. ACTION_MOVE: break; case MotionEvent. ACTION_UP: float tempY = event. getY (); LogUtils. d ("---> HomeActivity onTouch tempY = event. getY () "+ tempY); // slide from bottom up if (y-tempY)
  
   
MoveY) {popupWindow. showAtLocation (v, Gravity. BOTTOM, 0, 0);} break;} return true ;}
  
Some basic knowledge points (N2)

1. How to control the position of pop?

PopupWindow. showAtLocation ();

If you only want to set it under the space, you only need

PopupWindow. showAsDropDown (control );

Left side:

popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-popupWindow.getWidth(), location[1]);

Right side:

popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);  

2. In pop, all the widgets followstyle="@style/popTheme"How is this part operated?

Style !!

The Style is for the form Element Level, and changes the Style of the specified control or Layout.

Then let's talk about Theme:
Theme is for the form level and changes the form style.

2.1 HOW to use Style?

1. Create a file named style. xml in the res/values directory. Add a <resources> root node. 2. Add a globally unique name to <style> element for each style and topic, or add a parent class attribute. Later, we can use this name to apply the style, and the parent class attribute identifies the style inherited by the current style. 3. Declare one or more <items> within the <style> element. Each <item> defines a name attribute and the value of this style within the element. 4. You can apply resources defined in other XML files.

 

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.