如何在Android中轻击叠加层显示d出窗口?

如何在Android中轻击叠加层显示d出窗口?,第1张

概述在我的地图应用程序中,我在地图上显示一组叠加层.每当我点击叠加层,我需要显示一个d出窗口,像这样 任何人可以帮我解决这个问题吗? 是的,您可以通过点按地图设计我们的自助信息窗口来显示信息,如果您明白,请重播我,我将向您提供代码. public class MapLocationOverlay extends Overlay { private boolean isNameAddHol 在我的地图应用程序中,我在地图上显示一组叠加层.每当我点击叠加层,我需要显示一个d出窗口,像这样

任何人可以帮我解决这个问题吗?@H_404_3@解决方法 是的,您可以通过点按地图设计我们的自助信息窗口来显示信息,如果您明白,请重播我,我将向您提供代码.

public class MapLocationOverlay  extends Overlay  {    private boolean isnameAddHold=true;     private Bitmap bitmap,bitCross,bitMoreinformation;    int testX,testY,count=0;    int infoWindowOffsetX,infoWindowOffsetY;    public String name,address,argname,argAddress,argID;    //  Store these as global instances so we don't keep reloading every time    private Bitmap bubbleIcon,shadowIcon;    private MapLocationVIEwer mapLocationVIEwer;    double tolat,tolng;    private Paint   innerPaint,borderPaint,textPaint;    private boolean isRemovePriorPopup=false;    private boolean temp=true,first=true,firstDraw = true;    public boolean tempDefaule=true;    public Moreinformation myMoreinformation;    public PantryLocation location;    //  The currently selected Map Location...if any is selected.  This tracks whether an information      //  window should be displayed & where...i.e. whether a user 'clicked' on a kNown map location    private PantryLocation selectedMapLocation;      public MapLocationOverlay(MapLocationVIEwer mapLocationVIEwer,PantryLocation arglocation) {        this.mapLocationVIEwer = mapLocationVIEwer;        location=arglocation;        bubbleIcon = BitmapFactory.decodeResource(mapLocationVIEwer.getResources(),R.drawable.bubble);        shadowIcon = BitmapFactory.decodeResource(mapLocationVIEwer.getResources(),R.drawable.shadow);        bitmap = BitmapFactory.decodeResource(mapLocationVIEwer.getResources(),R.drawable.infowindow);        bitCross = BitmapFactory.decodeResource(mapLocationVIEwer.getResources(),R.drawable.crass);        bitMoreinformation = BitmapFactory.decodeResource(mapLocationVIEwer.getResources(),R.drawable.more_informations_new);    }    @OverrIDe    public boolean ontouchEvent(MotionEvent e,MapVIEw mapVIEw) {        // Todo auto-generated method stub         if (e.getAction() == 0)         {             this.tempDefaule=false;         }         if (e.getAction() == 1)         {             this.tempDefaule=false;         }         if (e.getAction() == 2)         {             this.tempDefaule=false;         }        return super.ontouchEvent(e,mapVIEw);    }           @OverrIDe    public boolean onTap(GeoPoint p,MapVIEw    mapVIEw)  {        //this.tempDefaule=false;        //  Store whether prior popup was displayed so we can call invalIDate() & remove it if necessary.        //  Next test whether a new popup should be displayed            selectedMapLocation = getHitMapLocation(mapVIEw,p);            mapVIEw.invalIDate();               //  Lastly return true if we handled this onTap()        return selectedMapLocation != null;    }    @OverrIDe    public voID draw(Canvas canvas,MapVIEw mapVIEw,boolean shadow) {        drawMapLocations(canvas,mapVIEw,shadow);        //this.tempDefaule=false;        drawInfoWindow(canvas,shadow);        //this.tempDefaule=false;        }    /**     * Test whether an information balloon should be displayed or a prior balloon hIDden.     */    private PantryLocation getHitMapLocation(MapVIEw    mapVIEw,GeoPoint   tapPoint) {        //  Track which MapLocation was hit...if any        PantryLocation hitMapLocation = null;        RectF hitTestRecr = new RectF();        Point screenCoords = new Point();        ArrayList<PantryLocation> iterator =mapLocationVIEwer.getMapLocations();        for(int i=0;i<iterator.size();i++) {                   PantryLocation testLocation = iterator.get(i);            //  Translate the MapLocation's lat/long coordinates to screen coordinates            mapVIEw.getProjection().topixels(testLocation.getPoint(),screenCoords);            // Create a 'hit' testing Rectangle w/size and coordinates of our icon            // Set the 'hit' testing Rectangle with the size and coordinates of our on screen icon            hitTestRecr.set(-bubbleIcon.getWIDth()/2,-bubbleIcon.getHeight(),bubbleIcon.getWIDth()/2,0);            hitTestRecr.offset(screenCoords.x,screenCoords.y);            //  Finally test for a match between our 'hit' Rectangle and the location clicked by the user            mapVIEw.getProjection().topixels(tapPoint,screenCoords);            //hitMapLocation = testLocation;            if (hitTestRecr.contains(screenCoords.x,screenCoords.y)) {                hitMapLocation = testLocation;                first = true;                isnameAddHold = true;                break;            }        }        testX=(int)screenCoords.x;        testY=(int)screenCoords.y;        //  Lastly clear the newMouseSelection as it has Now been processed        tapPoint = null;        if(hitMapLocation==null && selectedMapLocation!=null)        return selectedMapLocation;         return hitMapLocation;    }    private voID drawMapLocations(Canvas canvas,MapVIEw    mapVIEw,boolean shadow) {        int i=0;count++;        ArrayList<PantryLocation> iterator =mapLocationVIEwer.getMapLocations();        Point screenCoords = new Point();        for(i=0;i<iterator.size();i++) {                   PantryLocation location = iterator.get(i);            mapVIEw.getProjection().topixels(location.getPoint(),screenCoords);            //mapVIEw.getController().setCenter(location.getPoint());            if (shadow) {                //  Only offset the shadow in the y-axis as the shadow is angled so the base is at x=0;                 canvas.drawBitmap(shadowIcon,screenCoords.x,screenCoords.y - shadowIcon.getHeight(),null);            } else {                canvas.drawBitmap(bubbleIcon,screenCoords.x - bubbleIcon.getWIDth()/2,screenCoords.y - bubbleIcon.getHeight(),null);            }        }//      if(i==iterator.size()){//          this.tempDefaule=false;}if(tempDefaule==true){            PantryLocation location1 = this.location;            //mapVIEw.getProjection().topixels(location.getPoint(),screenCoords);            Point screenCoord = new Point();            mapVIEw.getController().setCenter(location1.getPoint());            mapVIEw.getController().setZoom(15);        //  tempDefaule=false;                //mapVIEw.getController().setCenter(location.getPoint());           }            //tempDefaule=false;    }           //mapVIEw.getProjection().topixels(location.getPoint(),screenCoord);            //canvas.drawBitmap(bubbleIcon,screenCoord.x - bubbleIcon.getWIDth()/2,screenCoord.y - bubbleIcon.getHeight(),null);            //mapVIEw.invalIDate();    private voID drawInfoWindow(Canvas canvas,MapVIEw  mapVIEw,boolean shadow) {        //this.tempDefaule=false;        if ( selectedMapLocation != null) {            if ( shadow) {                //  Skip painting a shadow in this tutorial            } else {                //  First determine the screen coordinates of the selected MapLocation                isRemovePriorPopup=true;                Point selDestinationOffset = new Point();                mapVIEw.getProjection().topixels(selectedMapLocation.getPoint(),selDestinationOffset);                //  Setup the info window with the right size & location                int INFO_WINDOW_WIDTH = 125;                int INFO_WINDOW_HEIGHT = 25;                RectF infoWindowRect = new RectF(0,100,20);                   RectF closeRect = new RectF(0,20,20);                  infoWindowOffsetX = selDestinationOffset.x-INFO_WINDOW_WIDTH/2;                 infoWindowOffsetY = selDestinationOffset.y-INFO_WINDOW_HEIGHT-bubbleIcon.getHeight();                 infoWindowRect.offset(infoWindowOffsetX+95,infoWindowOffsetY-45);                 closeRect.offset(infoWindowOffsetX+160,infoWindowOffsetY-90);                 Paint myPaintBlack=new Paint();                    Paint myPaintWhite=new Paint();                    myPaintWhite.setARGB(255,255,255);                //  Draw inner info window                canvas.drawRoundRect(infoWindowRect,5,getInnerPaint());                //  Draw border for info window                canvas.drawRoundRect(infoWindowRect,getborderPaint());                //  Draw the MapLocation's name                myPaintBlack.setcolor(color.BLACK);                myPaintBlack.setTextSize(20);                canvas.drawBitmap(bitmap,infoWindowOffsetX-50,infoWindowOffsetY-100,getInnerPaint());                if(isnameAddHold)                {                argID=selectedMapLocation.getID();                argname=selectedMapLocation.getname();                name=selectedMapLocation.getname();                tolat = selectedMapLocation.getLatitude();                tolng = selectedMapLocation.getLongitude();                if(name.length()>18)                name=selectedMapLocation.getname().substring(0,18)+"..";                argAddress=selectedMapLocation.getAddress();                address=selectedMapLocation.getAddress();                if(address.length()>30)                address=selectedMapLocation.getAddress().substring(0,30)+"..";                }                canvas.drawText(name,infoWindowOffsetX-45,infoWindowOffsetY-70,myPaintBlack);                myPaintBlack.setTextSize(13);                canvas.drawText(address,infoWindowOffsetY-55,myPaintBlack);            //  Draw inner info window                canvas.drawRoundRect(infoWindowRect,getborderPaint());                //  Draw the MapLocation's name                myPaintBlack.setcolor(color.CYAN);                myPaintBlack.setTextSize(11);                //canvas.drawText("Click for more info..",infoWindowOffsetX+105,infoWindowOffsetY-33,myPaintBlack);                canvas.drawBitmap(bitMoreinformation,infoWindowOffsetX+95,infoWindowOffsetY-45,getInnerPaint());                //canvas.drawBitmap(bitCross,infoWindowOffsetX+160,infoWindowOffsetY-90,getInnerPaint());            }        }        if(isRemovePriorPopup)        {        if(((testX>(infoWindowOffsetX+95)&&testX<(infoWindowOffsetX+195)))&&(testY>(infoWindowOffsetY-45)&&testY<(infoWindowOffsetY-25)))            {            if(temp){                try                {                    temp=false;                    isnameAddHold=false;                isRemovePriorPopup=false;                Context context=mapLocationVIEwer.cn;                Toast.makeText(context,"Loading...",Toast.LENGTH_SHORT).show();                Intent intent=new Intent(context,Moreinformation.class);                intent.putExtra("ID",argID);                intent.putExtra("name",argname);                intent.putExtra("Address",argAddress);                intent.putExtra("Latitude",tolat);                intent.putExtra("Longitude",tolng);                context.startActivity(intent);                }                catch (Exception ex)                {                    Log.d("Redirected Error :",ex.getMessage());                }        //canvas.drawText("This is for Testing",testX,myPaintBlack);            }}            else if(((testX>(infoWindowOffsetX+160)&&testX<(infoWindowOffsetX+180)))&&(testY>(infoWindowOffsetY-90)&&testY<(infoWindowOffsetY-70)))            {                if(isRemovePriorPopup)                {                 isRemovePriorPopup=false;                                   selectedMapLocation=null;                 draw(canvas,shadow);                // mapLocationVIEwer.setDZoom();                }            }        }    }    public Paint getInnerPaint() {        if ( innerPaint == null) {            innerPaint = new Paint();            innerPaint.setARGB(225,75,75); //gray            innerPaint.setAntiAlias(true);        }        return innerPaint;    }    public Paint getborderPaint() {        if ( borderPaint == null) {            borderPaint = new Paint();            borderPaint.setARGB(255,255);            borderPaint.setAntiAlias(true);            borderPaint.setStyle(Style.stroke);            borderPaint.setstrokeWIDth(2);        }        return borderPaint;    }    public Paint getTextPaint() {        if ( textPaint == null) {            textPaint = new Paint();            textPaint.setARGB(255,255);            textPaint.setAntiAlias(true);        }        return textPaint;    }}

在这段代码中,我设计了一个绘制信息窗口的函数@H_404_3@ 总结

以上是内存溢出为你收集整理的如何在Android中轻击叠加层显示d出窗口?全部内容,希望文章能够帮你解决如何在Android中轻击叠加层显示d出窗口?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1133666.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存