Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305
- Topic: User Interface Popupwindow (pop-up window)
-
The difference between Popupwindow and Alertdialog:
Alertdialog is non-blocking: Alertdialog pop-up, backstage can also do things.
Popupwindow is blocking: only allow us to operate the Popupwindow before Popupwindow exits, other operations are blocked.
Popupwindow (example):
Define a layout for Popupwindow.
Popupwindow.xml:
<?xml version= "1.0" encoding= "Utf-8"?><linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" android:layout_width =" fill_parent " android:layout_height =" fill_parent " android:background =" #336699 " android:orientation = "vertical" ; <imageview android:id
= "@+id/imageview" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:src = "@drawable/myimage" /> <linearlayout android:id = "@+id/linearlayout1" android:layout_width< /span>= "wrap_content" android:layout_height = "wrap_content" android:orientation = "vertical" ; <button android:id= "@+id/button1_sure" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "OK" /> <button android:id= "@+id/button2_cancel"android:layout_width=" Wrap_content "android:layout_height=" Wrap_content "android:text=" Cancel " /&G t; </linearlayout></linearlayout>
Mainactivity.java:
Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.text.InputType;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.ImageView;ImportAndroid.widget.PopupWindow;ImportAndroid.widget.TextView; Public class mainactivity extends Activity {Button button;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Button = (button) Findviewbyid (R.id.button1); Button.setonclicklistener (NewOnclicklistener () {@Override Public void OnClick(View arg0) {//TODO auto-generated method stubInitpopwindow (); } }); }Private void Initpopwindow() {//Load the Popupwindow layout fileView Contentview = Layoutinflater.from (Getapplicationcontext ()). Inflate (R.layout.popupwindow,NULL);//Declaration Popupwindow Pop-up windowPopupwindow Popupwindow =NewPopupwindow (NULL, -, -); Popupwindow.setcontentview (Contentview);//Get FocusPopupwindow.setfocusable (true);/** * Popupwindow Three display methods: * Showasdropdown (view view) Pop-up dialog box, located next to the View component Showasdropdown (view anchor, int x, int y) pops up the dialog box, positioned next to the view component, X y for offset showatlocation (View parent, int gravity, int x, int y) Popup dialog, position X y represents the offset, relative to the location of the parent layout * /Popupwindow.showasdropdown (button); ImageView ImageView = (ImageView) Contentview.findviewbyid (R.id.imageview); Button button_sure = (button) Contentview.findviewbyid (r.id.button1_sure); Button Button_cancel = (button) Contentview.findviewbyid (R.id.button2_cancel); }}
Operation Result:
Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305
Step by Step _android Development Course [26]_ User interface Popupwindow (pop-up window)