Custom Popupwindow+simpleadapter+anim

Source: Internet
Author: User



Package Com.example.mypopupwindow;import Java.util.arraylist;import Java.util.hashmap;import java.util.List;import;import;import Android.content.context;import;import;import Android.os.bundle;import Android.view.gravity;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.window;import Android.view.windowmanager;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.view.animation.scaleanimation;import Android.widget.adapterview;import Android.widget.adapterview.onitemclicklistener;import Android.widget.ImageView ; Import Android.widget.linearlayout.layoutparams;import Android.widget.listview;import Android.widget.PopupWindow ; Import Android.widget.simpleadapter;import Android.widget.toast;public class Mainactivity extends Activity Implements Onclicklistener {private Popupwindow msmsmorepopup;private ViEW smsmorepopulayout; List<map<string, string>> smsmorelist;private ImageView iv_common_more; @Overrideprotected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (r.layout.activity_main); Iv_common_more = (ImageView) Findviewbyid (; iv_common_ More.setonclicklistener (this); Initsmsmorepopudata (); Initpopup (); Msmsmorepopup.setondismisslistener (new Popupwindow.ondismisslistener () {@Overridepublic void Ondismiss () {Popupexitalpha ();}}); private void Initsmsmorepopudata () {smsmorelist = new arraylist<map<string, string>> (); map<string, string> map;map = new hashmap<string, string> (); Map.put ("Sms_more", "emptying Information"); Smsmorelist.add ( map); map = new hashmap<string, string> (); Map.put ("Sms_more", "Backup"); Smsmorelist.add (map); map = new hashmap< String, string> (); Map.put ("Sms_more", "import"); Smsmorelist.add (map); map = new hashmap<string, string> (); Map.put ("sMs_more "," recharge payment "); Smsmorelist.add (map); map = new hashmap<string, string> (); Map.put (" Sms_more "," settings "); Smsmorelist.add (map), map = new hashmap<string, string> (), Map.put ("Sms_more", "Exit Login"); Smsmorelist.add (map);} private void Initpopup () {smsmorepopulayout = view.inflate (this,r.layout.popupwindow_layout_right, NULL); ListView mmorepopuplist = (ListView) Smsmorepopulayout.findviewbyid (; msmsmorepopup = new Popupwindow (smsmorepopulayout); Msmsmorepopup.setwidth (layoutparams.wrap_content); MSmsMorePopup.setHeight ( layoutparams.wrap_content); Mmorepopuplist.setadapter (New Simpleadapter (Mainactivity.this,smsmorelist, R.layout.list_item_popupwindow,new string[] {"Sms_more"}, new int[] {}); Mmorepopuplist.setonitemclicklistener (New Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<? > Parent, View view,int position, long ID) {switch (position) {case 0://Mdialcontroller.dialmenu (dialcontroller.clear ); Toast.maketext (mainactivity.tHis, "Toast Test popup emptied record", 0). Show (); Morepopuexit (); Break;case 1:toast.maketext (Mainactivity.this, "Toast Test popup Backup", 0). Show (); Morepopuexit (); Break;case 2:toast.maketext (Mainactivity.this, "Toast Test popup Import", 0). Show (); Morepopuexit (); Break;case 3:toast.maketext (mainactivity.this, "Toast Test popup Recharge Payment", 0). Show (); Morepopuexit (); Break;case 4: Toast.maketext (Mainactivity.this, "Toast Test Popup Settings", 0). Show (); Morepopuexit (); break;case 5:morepopuexit (); break; Default:break;}} private void Morepopuexit () {scaleanimation animation = new Scaleanimation (1f, 0f, 1f, 0f,animation.relative_to_self, 1.0 F,animation.relative_to_self, 0.0f); animation.setduration (+); Animation.setfillafter (true); Smsmorepopulayout.startanimation (animation);p Opupexitalpha (); Animation.setanimationlistener (new Animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {} @Overridepublic void Onanimationrepeat (Animation Animation) {} @Overridepublic void Onanimationend (Animation Animation) { Msmsmorepopup.dismiss ();//Close}});}); MsmsmOrepopup.setfocusable (True); Msmsmorepopup.setbackgrounddrawable (new bitmapdrawable ()); Msmsmorepopup.setanimationstyle (; msmsmorepopup.setoutsidetouchable (true);} private void Popupshowalpha () {Windowmanager.layoutparams params = GetWindow (). GetAttributes ();p arams.alpha = 0.6f; GetWindow (). SetAttributes (params);} private void Popupexitalpha () {Windowmanager.layoutparams params = GetWindow (). GetAttributes ();p arams.alpha = 1.0f; GetWindow (). SetAttributes (params);} public int dp2px (context context, float DP) {final FLOAT scale = context.getresources (). Getdisplaymetrics (). density; return (int) (DP * scale + 0.5f);} private void onmesurelocation (view view, Popupwindow popup) {Rect frame = new Rect (); GetWindow (). Getdecorview (). Getwindowvisibledisplayframe (frame), int mmorepopupmargintop = + dp2px (mainactivity.this, n); int Mmorepopupmarginright = dp2px (mainactivity.this, +);p Opupshowalpha ();p opup.showatlocation (FindViewById ( Root), gravity.right|, MmorepOpupmarginright, Mmorepopupmargintop); scaleanimation animation = new Scaleanimation (0f, 1f, 0f, 1f,animation.relative_to_self, 1.0f, animation.relative_to_ self,0.0f); animation.setduration (+); Animation.setfillafter (true); view.startanimation (animation);} @Overridepublic void OnClick (View v) {switch (V.getid ()) {Case (msmsmorepopup.isshowing ()) { Msmsmorepopup.dismiss ();//Close}onmesurelocation (Smsmorepopulayout, msmsmorepopup); break;default:break;}}}

<relativelayout xmlns:android= "" xmlns:tools= "http// "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android          : id= "@+id/rl_root" tools:context= "com.example.popupwindowvslistview.MainActivity" > <relativelayout           Android:id= "@+id/rl_common_default" android:layout_width= "fill_parent" android:layout_height= "48DP" android:background= "@drawable/top_bg" > <imageview android:id= "@+id/iv_common_more              "Android:layout_width=" 34DP "android:layout_height=" 34DP "android:padding=" 5DP " Android:layout_alignparentright= "true" android:layout_centervertical= "true" android:l      ayout_marginright= "15DP" android:src= "@drawable/top_more_n" android:visibility= "visible"/> </RelativeLayout> </relativElayout>   


<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= " Android "    android:layout_width=" fill_parent "    android:layout_height=" fill_parent "    android:gravity=" Left "    android:orientation=" vertical ">        <textview         android:id=" @+id/tv_list_item "        android: Layout_width= "Fill_parent"        android:layout_height= "35DP"        android:textsize= "16DP"        android:textcolor= "#111111"        android:text= "AAA"        android:gravity= "center"        android:background= "@drawable/popupwindow _list_item_text_selector "                /></linearlayout>


<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= " Android "    android:layout_width=" fill_parent "    android:layout_height=" fill_parent ">    <listview        android:id= "@+id/lv_popup_list"        android:layout_width= "110DP"        android:layout_height= "Wrap_content"        android:background= "@drawable/layer_popup"        android:focusableintouchmode= "true"        android:divider= "@ Null "        android:listselector=" @drawable/popupwindow_list_item_text_selector "        android:paddingbottom=" 5DP "        android:paddingtop=" 5DP "        android:scrollbars=" None "/></linearlayout>


<?xml version= "1.0" encoding= "Utf-8"?> <layer-list  xmlns:android= "Http:// /android ">      <!--Bottom 2DP Shadow-      -          <item> <shape  android:shape=" Rectangle " >              <solid android:color= "#d9d9d9"/>              <corners android:radius= "5DP"/>                   </shape>      </item>            <!--white Top color--      <item android:bottom= "5px" >          <shape  Android:shape= "Rectangle" >               <solid android:color= "#d9d9d9"/>               <corners android:radius= "5DP"/ >          </shape>             </item>  </layer-list>  <!--  --

<?xml version= "1.0" encoding= "Utf-8"? ><selector  xmlns:android= " Android ">    <item android:state_pressed=" true "  android:drawable=" @drawable/more_popu_normal "/>    <item android:drawable= "@drawable/more_popu_pressed"/></selector>


<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://" >     <!--    displacement effect    fromxdelta= "0%p" refers to the x-axis that is relative to the parent control from the parent control's x=0 out of the start displacement    fromydelta= "0%p" refers to the y-axis relative to the parent control from the parent control's y= 0 out start displacement toxdelta= "100%p" refers to the x-axis of the parent control that reaches the x=100 position of the parent control, which is the    x-axis at the end of the screen    toydelta= "100%p" refers to the y-axis relative to the parent control reaching the parent control y= The 100 position is the x-axis at the end of the screen--     <scale        android:duration= "+"      android:pivotx= "100%"      android: Pivoty= "0%"        android:fromxscale= "1.0"      android:toxscale= "0.0"      android:fromyscale= "1.0"      android:toyscale= "0.0"/>   </set>     

<?xml version= "1.0" encoding= "Utf-8"?>  <resources>       <drawable name= "more_popu_pressed" ># d9d9d9</drawable>      <drawable name= "More_popu_normal" > #ffffff </drawable>  </resources >  

  <style name= "Animation" >        <item name= "android:windowexitanimation" > @anim/out</item>    </style>

Custom Popupwindow+simpleadapter+anim

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: 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.