Android Custom Imitation iOS pull-up menu implementation

Source: Internet
Author: User

Recently in doing a crooked nut to my outsourced project, the homepage needs to do a similar to the iOS kind of pull-down menu function, so a time to try various methods, what spinner, Drawlayout,slidingmenu and so on, can not do, Behind is really forced to write a pull-up menu control, incredibly still can make up for use!

You can call him mypullupmenu!. There is time I will encapsulate a release to GitHub.

As follows:

There are three functions that are implemented:

1. When the pull-up position does not exceed a certain distance, release automatically scroll down.

2. When the pull-up position exceeds a certain distance, release the automatic online scrolling until the menu is fully expanded.

3. When the menu scrolls to the top and stops scrolling, click the button menu to automatically roll back to the bottom


Implementation steps:

1. First write the Mypullupmenu XML interface:

    <linearlayout android:id= "@+id/main_textmenu" android:layout_width= "Match_parent" Android:layo ut_height= "match_parent" android:orientation= "vertical" > <imagebutton android:id= "@ +id/main_dropdownbtn "android:layout_width=" 80DP "android:layout_height=" 30DP "Android:la             Yout_alignparentbottom= "true" android:layout_centerhorizontal= "true" android:layout_gravity= "center" android:background= "@drawable/main_shape0" android:paddingbottom= "5DP" Android:paddingle            ft= "20DP" android:paddingright= "20DP" android:paddingtop= "5DP" android:scaletype= "Fitxy" android:src= "@drawable/main_bottonbtn"/> <linearlayout android:layout_width= "Match_pare NT "android:layout_height=" 0DP "android:layout_weight=" 1 "android:orientation=" vertical "&            Gt <com.wHale.nangua.omegaenglish.view.TextViewKaiti android:id= "@+id/main_btn1" android:layout_width = "Match_parent" android:layout_height= "40DP" android:background= "@drawable/main_shape_txtbtn "android:gravity=" center "android:text=" photo "android:textcolor=" @android: Colo                R/white "android:textsize=" 30sp "/> <com.whale.nangua.omegaenglish.view.textviewkaiti Android:id= "@+id/main_btn2" android:layout_width= "Match_parent" Android:layout_hei                ght= "40DP" android:background= "@drawable/main_shape_txtbtn" android:gravity= "center" android:text= "Teacher" android:textcolor= "@android: Color/white" android:textsize= "30SP"/&            Gt <com.whale.nangua.omegaenglish.view.textviewkaiti android:id= "@+id/main_btn3" Android:lay Out_width= "Match_parent" android:layout_height= "40DP" android:background= "@drawable/main_shape_txtbtn "android:gravity=" center "android:text=" Upgrade "android:textcolor=" @android: Colo                R/white "android:textsize=" 30sp "/> <com.whale.nangua.omegaenglish.view.textviewkaiti Android:id= "@+id/main_btn4" android:layout_width= "Match_parent" Android:layout_hei                ght= "40DP" android:background= "@drawable/main_shape_txtbtn" android:gravity= "center" android:text= "Activity" android:textcolor= "@android: Color/white" android:textsize= "30SP"/&            Gt <com.whale.nangua.omegaenglish.view.textviewkaiti android:id= "@+id/main_btn5" Android:lay Out_width= "Match_parent" android:layout_height= "40DP" android:background= "@drawable/main_sha Pe_txtbtn"android:gravity=" center "android:text=" QR Scan "android:textcolor=" @android: Co                Lor/white "android:textsize=" 30sp "/> <com.whale.nangua.omegaenglish.view.textviewkaiti Android:id= "@+id/main_btn6" android:layout_width= "Match_parent" Android:layout_h                eight= "40DP" android:background= "@drawable/main_shape_txtbtn" android:gravity= "center" android:text= "dictionary" android:textcolor= "@android: Color/white" android:textsize= "30SP"                /> <com.whale.nangua.omegaenglish.view.textviewkaiti android:id= "@+id/main_btn7" Android:layout_width= "Match_parent" android:layout_height= "40DP" android:background= "@ DRAWABLE/MAIN_SHAPE_TXTBTN "android:gravity=" center "android:text=" shop "Android : textcolor= "@android: ColOr/white "android:textsize=" 30sp "/> <com.whale.nangua.omegaenglish.view.textviewkaiti Android:id= "@+id/main_btn8" android:layout_width= "Match_parent" android:layout_he                ight= "40DP" android:background= "@drawable/main_shape_txtbtn" android:gravity= "center" android:text= "recommended" android:textcolor= "@android: Color/white" android:textsize= "30SP"/                > <com.whale.nangua.omegaenglish.view.textviewkaiti android:id= "@+id/main_btn9" Android:layout_width= "Match_parent" android:layout_height= "40DP" android:background= "@d RAWABLE/MAIN_SHAPE_TXTBTN "android:gravity=" center "android:text=" Settings "Android : textcolor= "@android: Color/white" android:textsize= "30sp"/> <com.whale.nangua.omegaenglish . View.     Textviewkaiti           Android:id= "@+id/main_btn10" android:layout_width= "Match_parent" Android:layout_h                eight= "40DP" android:background= "@drawable/main_shape_txtbtn" android:gravity= "center" android:text= "News" android:textcolor= "@android: Color/white" android:textsize= "30SP"                /> <com.whale.nangua.omegaenglish.view.textviewkaiti android:id= "@+id/main_btn11" Android:layout_width= "Match_parent" android:layout_height= "40DP" android:background= " @drawable/main_shape_txtbtn "android:gravity=" center "android:text=" About Us "and Roid:textcolor= "@android: Color/white" android:textsize= "30sp"/> </LinearLayout>
:


2. Logical function Implementation:

First, you need to move the layout file to the bottom during the loading process:

Main_textmenulayout.sety (screenHeight-30 * scale);
Here the ScreenHeight is the screen height, 30 is the button height, scale is the screen pixel density ratio.

Next, you need to get the height of the entire space main_textmenulayout_height:

Main_textmenulayout_height = * Scale * one + * scale;
This can also be changed to get the entire space height then multiplied by the zoom ratio to zoom, I write this is very unscientific, violating the reusability of Qaq.

After that, the touch event can be judged on the Ontouch of the button:

        Main_dropdownbtn.setontouchlistener (New View.ontouchlistener () {@Override public boolean on                Touch (View V, motionevent event) {Y = (int) Event.getrawy ();                Objectanimator animator; Switch (event.getaction ()) {Case MotionEvent.ACTION_MOVE:if ((Y <= (screenh EIGHT-30 * scale)) && (Y >= screenheight-main_textmenulayout_height)) {main_t                        Extmenulayout.sety (Y);                    } break;                             Case MotionEvent.ACTION_UP:if (Y <= (screenheight-main_textmenulayout_height + x scale)) {                        Break                        } int yposition = (int) (SCREENHEIGHT-MAIN_TEXTMENULAYOUT_HEIGHT/2); if (Y <= yposition) {animator = Objectanimator.offloat (Main_textmenulayout, "Translationy", screenheight-main_textmenulayout_height); } else {animator = Objectanimator.offloat (Main_textmenulayout, "Translationy", ScreenHeight-                        * scale);                        } animator.setduration (300);                        Animator.start ();                Break            } return false; }        });
Finally, there are button click-down events that need to be defined in the OnClick method in the button's Onclicklistener:

Objectanimator animator = Objectanimator. offloat (main_textmenulayout"Translationy"scale) ; Animator.setduration (+); Animator.start ();



Because it is a commercial outsourcing project, the source code will not provide, so, the need to private chat me.


Android Custom Imitation iOS pull-up menu implementation

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.