Not too many tricks, there is no very complex technology, is the use of simple popupwindow, you can achieve click to pop a custom View,view can be casually designed, commonly used can put a ListView.
Demo I just a click to show, simple use of the fade in the animation effect, there is no exquisite picture resources, look also ugly, but such a short time, let you master a very useful technology, you can expand, not very good?
Nonsense not to say, directly on the code:
Mainactivity.java
[Java]View Plaincopy
- Public class Mainactivity extends Activity implements Onclicklistener {
- private Popupwindow Popupwindow;
- Private button button;
- @Override
- protected void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Setcontentview (R.layout.activity_main);
- Button = (button) Findviewbyid (R.id.button1);
- Button.setonclicklistener (this);
- }
- @Override
- public void OnClick (View v) {
- switch (V.getid ()) {
- Case R.id.button1:
- if (Popupwindow! = null&&popupwindow.isshowing ()) {
- Popupwindow.dismiss ();
- return;
- } Else {
- Initmpopupwindowview ();
- Popupwindow.showasdropdown (V, 0, 5);
- }
- Break ;
- Default:
- Break ;
- }
- }
- public void Initmpopupwindowview () {
- //// Get a view of the custom layout file Pop.xml
- View CustomView = Getlayoutinflater (). Inflate (R.layout.popview_item,
- null, false);
- //Create Popupwindow instances, 200,150 are width and height, respectively
- Popupwindow = New Popupwindow (CustomView, 280);
- //Set animation effect [R.style.animationfade is defined by oneself beforehand]
- Popupwindow.setanimationstyle (R.style.animationfade);
- //Custom View Add Touch event
- Customview.setontouchlistener (new Ontouchlistener () {
- @Override
- Public Boolean OnTouch (View V, motionevent event) {
- if (Popupwindow! = null && popupwindow.isshowing ()) {
- Popupwindow.dismiss ();
- Popupwindow = null;
- }
- return false;
- }
- });
- /** Here you can implement the function of the custom view * /
- Button Btton2 = (button) Customview.findviewbyid (R.id.button2);
- Button Btton3 = (button) Customview.findviewbyid (R.id.button3);
- Button Btton4 = (button) Customview.findviewbyid (R.ID.BUTTON4);
- Btton2.setonclicklistener (this);
- Btton3.setonclicklistener (this);
- Btton4.setonclicklistener (this);
- }
- }
Activity_main.xml
[Java]View Plaincopy
- <relativelayout xmlns:android="Http://schemas.android.com/apk/res/android"
- xmlns:tools="Http://schemas.android.com/tools"
- Android:layout_width="Match_parent"
- android:layout_height="Match_parent"
- android:background="#000000"
- Tools:context=". Mainactivity ">
- <button
- android:id="@+id/button1"
- Android:layout_width="Match_parent"
- android:layout_height="Wrap_content"
- android:layout_alignparentleft="true"
- android:layout_alignparenttop="true"
- android:gravity="center"
- android:background="#C0C0C0"
- android:text="Click Drop-down list"/>
- </RelativeLayout>
XML for Custom View
[Java]View Plaincopy
- <relativelayout xmlns:android="Http://schemas.android.com/apk/res/android"
- xmlns:tools="Http://schemas.android.com/tools"
- Android:layout_width="Match_parent"
- android:layout_height="Match_parent"
- android:background="#C0C0C0" >
- <button
- android:id="@+id/button2"
- Android:layout_width="200DP"
- android:layout_height="Wrap_content"
- android:layout_alignparentleft="true"
- android:layout_alignparenttop="true"
- android:paddingright="70DP"
- android:text="Viviens"/>
- <button
- android:id="@+id/button3"
- Android:layout_width="200DP"
- android:layout_height="Wrap_content"
- android:layout_alignparentleft="true"
- android:layout_below="@+id/button2"
- android:paddingright="70DP"
- android:text="Mryang"/>
- <button
- android:id="@+id/button4"
- Android:layout_width="200DP"
- android:layout_height="Wrap_content"
- android:layout_alignparentleft="true"
- android:layout_below="@+id/button3"
- android:paddingright="70DP"
- android:text="Zhang Xiaoda"/>
- </RelativeLayout>
Animation effect:
Inputodown.xml Entering the screen
[Java]View Plaincopy
- <?xml version="1.0" encoding="UTF-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android" >
- <translate
- android:duration="
- Android:fromydelta=" -100%"
- Android:toydelta="0"/>
- </set>
Outdowntoup.xml
[Java]View Plaincopy
- <?xml version="1.0" encoding="UTF-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android" >
- <translate
- android:duration="
- Android:fromydelta="0"
- Android:toydelta=" -100%"/>
- </set>
Styles.xml
[HTML]View Plaincopy
- <style name="Animationfade">
- <!--Popupwindow effect and left
- <item name="android:windowenteranimation"> @anim/inuptodown</Item >
- <item name="android:windowexitanimation"> @anim/outdowntoup</Item>
- </style>
Implementation results:
Demo Address:
http://download.csdn.net/detail/mad1989/5518035