So zeigen Sie ein benutzerdefiniertes Dialogfeld an einer bestimmten position?

Ich habe einen Button, dessen Klick öffnet sich ein Dialogfeld.Das Dialogfeld wird immer angezeigt, in der Mitte.Aber ich möchte, um es anzuzeigen einfach unter der Schaltfläche.Wie Sie dies tun ?

Ich habe versucht mit popup-Fenster auch.Hier ist der code

private void showPopup(final Activity context, Point p)
    {
        Display display = getWindowManager().getDefaultDisplay(); 
        width = display.getWidth();  //deprecated
        height = display.getHeight();  //deprecated

        int popupWidth =width;
        int popupHeight =height;

       //Inflate the popup_layout.xml
       LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
       LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       View layout = layoutInflater.inflate(R.layout.datepicker_popup, viewGroup);

       //Creating the PopupWindow
       final PopupWindow popup = new PopupWindow(context);
       popup.setContentView(layout);
       popup.setWidth(popupWidth+p.x);
       popup.setHeight(popupHeight+p.y);
       popup.setFocusable(true);

       //Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
       int OFFSET_X = 7;
       int OFFSET_Y = 65;

       //Clear the default translucent background
       popup.setBackgroundDrawable(new BitmapDrawable());

       //Displaying the popup at the specified location, + offsets.
       popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);



       //Getting a reference to Close button, and close the popup when clicked.
       Button close = (Button) layout.findViewById(R.id.close);
       close.setOnClickListener(new OnClickListener()
       {
           /* disable(content_view);*/
         @Override
         public void onClick(View v) 
         {
            popup.dismiss();
         }
       });

       }
InformationsquelleAutor Nevaeh | 2014-03-12
Schreibe einen Kommentar