dialog implementing the Spinner drop-down list effect

Source: Internet
Author: User
Tags stub

First look at the effect, I feel better than spinner effect, record the implementation process.

Final string[] Levelarray = Getresources (). Getstringarray (R.array.contact_level); Re_layout_spinner.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {//TODO Au
					to-generated method Stub if (!isexpand) {Dialog = New dialog (mself);
					Dialog.requestwindowfeature (Window.feature_no_title);
					ListView Mlistview = new ListView (mself);
					Mlistview.setcachecolorhint (color.transparent);
					Mlistview.setadapter (New Leveladapter ());
					Mlistview.setbackgroundresource (R.DRAWABLE.INFORMATION_BLUE_BG); Mlistview.setonitemclicklistener (New Onitemclicklistener () {@Override public void Onitemclick (adapterview&lt ;? > Parent, view view, int position, long ID) {//TODO auto-generated Method stub Tv_level.settext (levelar
							Ray[position]);
								if (dialog! = null) {Dialog.dismiss ();
								dialog = null;
							Isexpand = false;
					}
						}
					});
			Dialog.setcontentview (Mlistview);		Dialog.setondismisslistener (New Dialoginterface.ondismisslistener () {@Override public void Ondismiss (Dialo
						Ginterface dialog) {//TODO auto-generated method Stub isexpand = false;
					}
					});
					Window Dialogwindow = Dialog.getwindow ();
					Dialogwindow.setbackgrounddrawable (New colordrawable (Android.graphics.Color.RED)); Dialogwindow.setgravity (Gravity.left |
					Gravity.top);
					Windowmanager.layoutparams LP = Dialogwindow.getattributes ();
					Lp.dimamount = 0f;
					int[] location = new INT[2];
					Re_layout_spinner.getlocationonscreen (location);
					Rect out = new rect ();
					Re_layout_spinner.getwindowvisibledisplayframe (out);
					lp.x = location[0];
					LP.Y = location[1]-out.top + re_layout_spinner.getheight ();
					Lp.width = Re_layout_spinner.getwidth ();
					Lp.height = layoutparams.wrap_content;
					Dialogwindow.setattributes (LP);
					Dialog.show ();
				Isexpand = true; } else {if (dialog! = null) {DIALOG.DIsmiss ();
					dialog = null; }
				}
			}
		});

New Leveladapter () put a textview, the other needs to say is the dialog pop-up location settings, I want to let it stick to my relativelayout appear to get this relativelayout position, and re_ Layout_spinner.getlocationonscreen (location), get the position from the top of the screen, so also get the height of the status bar, minus this height can be correctly displayed in the position we need.

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.