The MySQL stored procedure contains transactions, and incoming SQL data is executed

Source: Internet
Author: User

There is a need to: Click on a Picture button, the top of the button to pop a box, according to the contents of the frame of the page to do different display. This is actually not difficult, mainly to control the display of the frame, so that the frame is displayed in the middle of the picture.

The first is the use of the Popupwindow, but Popupwindow can not add a translucent mask to the page outside the window, of course, a special layer on the page as a mask view, but it is obvious that the code becomes very disgusting, and then replaced by dialog, Because the dialog pop-up will automatically add a mask, but this time, the frame display position of the y-coordinate is not right, then a check, the original dialog default is with the title, as long as the title can be removed, see the code:

Activity_main.xml:

<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 " >    <imageview        android:id= "@+id/img1"        android:layout_width= "wrap_content"        android:layout_ height= "Wrap_content"        android:layout_centerinparent= "true"        android:src= "@drawable/img"/>        < ImageView        android:id= "@+id/img2"        android:layout_width= "wrap_content"        android:layout_height= " Wrap_content "        android:layout_torightof=" @id/img1 "        android:layout_marginleft=" 50DP "        android: layout_aligntop= "@id/img1"        android:src= "@drawable/img"/></relativelayout>
Mainactivity.java:
public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); final ImageView img1 = (ImageView) This.findviewbyid ( R.ID.IMG1); Img1.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View v) {usepopup (IMG1);}}); Final ImageView Img2 = (ImageView) This.findviewbyid (R.ID.IMG2); Img2.setonclicklistener (new View.onclicklistener () {@ overridepublic void OnClick (View v) {usedialog (IMG2);}});}}
Menu.xml
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/         Android "Android:layout_width=" Wrap_content "android:layout_height=" wrap_content "> <relativelayout        Android:id= "@+id/menu_layout" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_centerhorizontal= "true" > <textview android:id= "@+id/menu_camera" android:l        Ayout_width= "100DP" android:layout_height= "50DP" android:gravity= "center" android:clickable= "true" android:text= "Camera photo" android:textsize= "16sp" android:textcolor= "@android: Color/black" Android:bac        Kground= "@android: Color/white"/> <view android:id= "@+id/menu_sep" android:layout_width= "100DP" android:layout_height= "1DP" android:background= "@android: Color/black" android:layout_below= "@id/menu_ Camera "/> <textview       Android:id= "@+id/menu_album" android:layout_width= "100DP" android:layout_height= "50DP" Android        : layout_below= "@id/menu_sep" android:gravity= "center" android:clickable= "true" android:text= "Pick picture" Android:textsize= "16sp" android:textcolor= "@android: Color/black" android:background= "@android: Color/whi TE "/></relativelayout> <imageview android:id=" @+id/arrow_up "Android:layout_width=" W Rap_content "android:layout_height=" wrap_content "android:layout_below=" @id/menu_layout "Android:layo ut_margintop= "0DP" android:layout_centerhorizontal= "true" android:src= "@drawable/arrow_up"/> </rela Tivelayout>
MainActivity.java :
private void Usepopup (final ImageView anchor) {//reference: Http://www.cnblogs.com/sw926/p/3230659.htmlLayoutInflater Minflater = Layoutinflater.from (this); ViewGroup Rootview = (viewgroup) minflater.inflate (r.layout.menu, NULL); Rootview.setlayoutparams (New Layoutparams (Layoutparams.wrap_content, layoutparams.wrap_content)); final Popupwindow popup = new Popupwindow (this); Be sure to set the width height before//setcontentview, otherwise it will not show popup.setwidth ( WindowManager.LayoutParams.WRAP_CONTENT);p opup.setheight (WindowManager.LayoutParams.WRAP_CONTENT);//Remove the default background Popup.setbackgrounddrawable (New Colordrawable (Android). r.color.transparent));p Opup.setcontentview (Rootview);//The Popupwindow disappears when the space is clicked Popup.settouchable (true); Popup.setoutsidetouchable (TRUE);//If focusable is false, in an activity pops up a popupwindow, press the back key, because Popupwindow has no focus, Will exit the activity directly. If focusable is ejected for True,popupwindow, all touch screens and physical keys are popupwindows processed. Popup.setfocusable (TRUE);//Calculate the frame position int[] xy = Calcpopupxy (rootview,anchor);//without any gravity, use absolute (x, y) Coordinate popup.showatlocation (View) anchor.getparent (), GraVity.no_gravity, Xy[0], xy[1]);} private void Usedialog (final ImageView anchor) {Layoutinflater Minflater = Layoutinflater.from (this); ViewGroup Rootview = (viewgroup) minflater.inflate (r.layout.menu, NULL); Rootview.setlayoutparams (New Layoutparams (Layoutparams.wrap_content, layoutparams.wrap_content));D ialog Dialog = New Dialog (this); Windowmanager.layoutparams params = Dialog.getwindow (). GetAttributes ();p arams.width = Windowmanager.layoutparams.wrap_content;params.height = windowmanager.layoutparams.wrap_content;//Remove the default background, The following two can be Dialog.getwindow (). setbackgrounddrawable (New Colordrawable (Android). r.color.transparent));//dialog.getwindow (). Setbackgrounddrawableresource (Android. r.color.transparent);//http://stackoverflow.com/questions/12348405/ Dialog-is-bigger-than-expected-when-using-relativelayout//dialog default is the title of the Dialog.requestwindowfeature ( Window.feature_no_title);//Remove the title, otherwise it will affect the height calculation, must be called before Setcontentview, finally understand that there is a setting theme the purpose of the constructor Dialog.setcontentview ( Rootview);//Calculate the frame position int[] xy = CalcpopupXY (rootview,anchor); The default value for//gravity is Gravity.center, which is Gravity.center_horizontal | gravity.center_vertical.//Reference: Http://www.cnblogs.com/angeldevil/archive/2012/03/31/2426242.htmldialog.getWindow (). Setgravity (Gravity.left | Gravity.top);p arams.x = xy[0];p arams.y = xy[1];d ialog.show ();} Reference:http://blog.csdn.net/johnny901114/article/details/7839512  Private int[] Calcpopupxy (view Rootview, view anchor) {int w = View.MeasureSpec.makeMeasureSpec (0,      View.MeasureSpec.UNSPECIFIED);     int h = View.MeasureSpec.makeMeasureSpec (0,view.measurespec.unspecified);      Rootview.measure (W, h);    int popupwidth = Rootview.getmeasuredwidth ();    int popupheight = Rootview.getmeasuredheight (); Rect anchorrect = getviewabsolutelocation (anchor); int x = Anchorrect.left + (anchorrect.right-anchorrect.left)/2-popup    Width/2;int y = Anchorrect.top-popupheight;return new int[]{x,y};}    public static Rect getviewabsolutelocation (view view) {if (view = = null) {return new Rect (); }//gets the coordinates of the view relative to the screen int[] location = new Int[2]; View.getlocationonscreen (location);//This is the absolute coordinate that gets relative to the screen, and View.getlocationinwindow (location); is to get the relative coordinates on the window, in this case there is only one window, both equal//get the width of the view int width = view.getmeasuredwidth (); int height = View.getmeasuredheight ();//Gets the view's rectrect rect = new rect (); rect.left = Location[0];rect.top = Location[1];rect.right = Rect.left+ Width;rect.bottom = rect.top + Height;return rect;} 


SOURCE in: http://download.csdn.net/download/goldenfish1919/7291951


To summarize:

(1) Popupwindow Be sure to set the width height before the display, dialog no this limit.

(2) Popupwindow does not respond to the back of the physical keyboard by default, unless the display is set to Popup.setfocusable (True), and dialog disappears when you click Back.

(3) Popupwindow will not add a mask to the rest of the page, and dialog will.

(4) Popupwindow No title, dialog default title, can be Dialog.requestwindowfeature (window.feature_no_title);

(5) The gravity should be set when both are displayed. If not set, dialog default is Gravity.center.

(6) Both have a default background and are available via setbackgrounddrawable (new Colordrawable (Android). r.color.transparent)); remove.





Related Article

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.