Turn: Imitation qq long Press the popup function menu

Source: Internet
Author: User

The pop-up context menu commonly used by Android apps is List-style. QQ list, pop-up on top of the bubble effect menu,

Here's how to write this effect:

Picture resources: Two pictures can be spliced into the effect.

First, we need to write the layout file:
Layout_pop.xml (mipmap is a reference picture of Android Studio, formerly used @drawable/xxx)

<?xml version= "1.0" encoding= "Utf-8"?><RelativelayoutXmlns:android="Http://schemas.android.com/apk/res/android"Android:layout_width="Wrap_content"android:layout_height="Wrap_content"android:padding="10DP" ><ButtonAndroid:id="@+id/bt_l"style="@style/popbtuton"Android:layout_width="Wrap_content"android:layout_height="Wrap_content"Android:background= "@mipmap/bg_pop_l_t" android:text=  "copy"/> <button android:id=" @+id/bt_r "style=" @style/popbtuton "android:layout_width=" wrap _content "android:layout_height=" wrap_content "android:layout_torightof= "@+id/bt_l"  Android:background= "@mipmap/bg_pop_r_t" android:text=< Span class= "Hljs-value" > "reply"/></RELATIVELAYOUT>    

Layout effect

Next is the focus:
Post Code First
Popoptionutil.java

Package Com.mjc.popdemo;Import Android.content.Context;Import android.graphics.drawable.BitmapDrawable;Import android.view.Gravity;Import Android.view.LayoutInflater;Import Android.view.View;Import Android.view.ViewGroup;Import Android.widget.Button;Import Android.widget.PopupWindow;/** * Created by imac on 15/7/8. */PublicClassPopoptionutil {Private Context Mcontext;Privateint popupwidth;Privateint popupheight;Private Popupwindow Popupwindow;Private Popclickevent mevent;Private Button prebt;Private Button NEXTBT;PublicPopoptionutil (Context context) {Mcontext = context; View Popupview = Layoutinflater.from (Mcontext). Inflate (R.layout.layout_pop,NULL); PREBT = (Button) Popupview.findviewbyid (r.id.bt_l); NEXTBT = (Button) Popupview.findviewbyid (R.id.bt_r); Popupwindow =New Popupwindow (Popupview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,true); Popupwindow.setbackgrounddrawable (New Bitmapdrawable ()); Popupview.measure (View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); Popupwidth = Popupview.getmeasuredwidth (); Popupheight = Popupview.getmeasuredheight (); }PublicvoidShow (view view) {initevent ();int[] location =Newint[2]; View.getlocationonscreen (location); Popupwindow.showatlocation (View, gravity.no_gravity, (location[0] + view.getwidth ()/2)-popupwidth/2, location[1]-popupheight); }Publicvoid setonpopclickevent (popclickevent mEvent) {this.mevent = mevent; } private void initEvent () {if (mevent! = null) {Prebt.setonclicklistener (new View.onclicklistener () { @Override  Public void onclick (view view) {Mevent.onpreclick ();}); Nextbt.setonclicklistener (new View.onclicklistener () {@ Override public void onClick (View View) {Mevent.onnextclick ();}}); } }} 

Where event is a custom interface that listens for two button events

Here is
Popclickevent.java

public interface PopClickEvent {    public void onPreClick(); public void onNextClick();}

How to use:

Package Com.mjc.popdemo;Import Android.os.Bundle;Import android.support.v7.app.AppCompatActivity;Import Android.view.Menu;Import Android.view.MenuItem;Import Android.view.View;Import Android.widget.Toast;PublicClassMainactivityExtendsappcompatactivity {View bt; Popoptionutil MPop;@OverrideProtectedvoidOnCreate (Bundle savedinstancestate) {Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); BT = Findviewbyid (r.id.test); MPop =New Popoptionutil (this); Mpop.setonpopclickevent (New Popclickevent () {@OverridePublicvoid onpreclick () {Toast.maketext (Mainactivity.this," pinned ", Toast.length_short). Show (); }  @Override public void onnextclick () {Toast.maketext (Mainactivity. "delete", Toast.length_short). Show (); } }); Bt.setonlongclicklistener (new View.onlongclicklistener () {  @Override public boolean Span class= "Hljs-title" >onlongclick (view view) {mpop.show (view); Bt.setselected (true); Span class= "Hljs-keyword" >return true;}); }} 

Final effect:

Isn't it simple? Just try it.

Reference: http://blog.csdn.net/u011494050/article/details/38691475

http://blog.csdn.net/meijian531161724/article/details/46804281

Turn: Imitation qq long Press the popup function menu

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.