Reprint please indicate the source: Wang 亟亟 's way of Daniel
Ability OK small partner can not see N2, source at the bottom
Earlier this morning a andorid group of small Partners asked me some popupwindow question, just last night I noticed a QQ music menu bar, then today follow that implementation (UI blind do you understand)
First up and down the original:
Put our effect again (except that it looks like nothing, haha ha):
Feature implementation:
1: Bottom Popupwindow rendering
2: Gesture Action action control
3: Button Action controls
4: Click events inside the control
How does?
Analysis:
First of all, this is a standard popupwindow,pop at the bottom (after all) there are 2 rows inside, each row has a series of buttons,
Each button has its Click event, pop support gesture display or hidden, this series is what we want to do, let us look at the code with the needs.
Package Structure:
This time not like before, write a demo I lead a bunch of bags, this time using the log library:
Gradle:
‘com.apkfuns.logutils:library:1.0.6‘
The implementation class is apublic class HomeActivity extends Root implements View.OnClickListener, View.OnTouchListener
In the example there are a lot of findid things, in fact, can use annotations to do these things, you can refer to http://blog.csdn.net/ddwhan0123/article/details/47399259
Onclicklistener to solve all of our click events, from the button to the small icon in the pop
Ontouchlistener to solve the business of our sliding operation, hide/show pop with
Specific slide Hide/Show Method:
Movey is a sliding distance judgment value, define multiple fields you decide for yourself.
Motionevent.action_down Touch the screen at the moment to record a coordinate.
MOTIONEVENT.ACTION_UP the coordinates of the finger when leaving, then?
Gaga minus minus is the result, isn't so easy?
@Override PublicBooleanOnTouch(View V, motioneventEvent) {Switch(Event. Getaction ()) { Casemotionevent.action_down:y=Event. GetY (); LOGUTILS.D ("--->homeactivity onTouch y=event.gety ()"+y); Break; CaseMotionevent.action_move: Break; CaseMOTIONEVENT.ACTION_UP:floattempy=Event. GetY (); LOGUTILS.D ("--->homeactivity onTouch tempy=event.gety ()"+tempy);//slide from bottom to top if(Y-tempy<movey) {Dissmisspop ();//slide from top down}Else if(Y-tempy>movey) {popupwindow.showatlocation (V, Gravity.bottom,0,0); } Break; }return true; }
Some basic points of knowledge (N2)
1. How do I control the location of the pop?
Popupwindow.showatlocation ();
If you just set the below space, you only need to
popupWindow.showAsDropDown(控件);
Left:
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-popupWindow.getWidth(), location[1]);
Right:
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);
In 2.pop, all small controls are followed style="@style/popTheme"
, and how does this part work?
style!!
Style is for the level of the form element, changing the style of the specified control or layout.
Then say the theme:
Theme is for the form level, change the form style
2.1 How do I use Style?
1. Create a new file named Style.xml in the Res/values directory. Add a <resources>
root node.
2. For each style and theme, <style>
Add a globally unique name to element and optionally add a parent attribute. In the back we can use the name to apply the style, and the parent attribute identifies which style the current style is inherited from.
3. Within the <style>
element, declare one or more <item>
, each defining a <item>
name attribute, and defining the value of this style within the element.
4. You can apply resources that are defined in other XML.
Source Address: Https://github.com/ddwhan0123/BlogSample/tree/master/PopupWindowDemo
Remember to order a praise Oh!!
Popupwindow implementation of iOS QQ music pull-up menu bar (support gesture and click action)