我想在圆形视图中显示地图,其中圆形的外部区域充满了颜色.我提到了一个Draw transparent circle filled outside的帖子.但现在问题是触摸事件.可以通过外部圆形视图触摸地图,而我需要在圆形视图(地图可见的地方)内仅触摸(缩放或移动)地图.
我试过的,
> setEnabled = false
> clickable = false
但仍然从外圆视图触摸地图.
是否可以实现从圆形视图内部触摸该地图.
public class RadiusOverlayVIEw extends linearLayout { private Bitmap windowFrame; public RadiusOverlayVIEw(Context context) { super(context); } public RadiusOverlayVIEw(Context context, AttributeSet attrs) { super(context, attrs); } public RadiusOverlayVIEw(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TargetAPI(Build.VERSION_CODES.LolliPOP) public RadiusOverlayVIEw(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @OverrIDe protected voID dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (windowFrame == null) { createWindowFrame(); // Lazy creation of the window frame, this is needed as we don't kNow the wIDth & height of the screen until draw time } canvas.drawBitmap(windowFrame, 0, 0, null); } @OverrIDe public boolean isEnabled() { return false; } @OverrIDe public boolean isClickable() { return false; } protected voID createWindowFrame() { windowFrame = Bitmap.createBitmap(getWIDth(), getHeight(), Bitmap.Config.ARGB_8888); // Create a new image we will draw over the map Canvas osCanvas = new Canvas(windowFrame); // Create a canvas to draw onto the new image RectF outerRectangle = new RectF(0, 0, getWIDth(), getHeight()); Paint paint = new Paint(Paint.ANTI_AliAS_FLAG); // Anti alias allows for smooth corners paint.setcolor(color.CYAN); // This is the color of your activity background osCanvas.drawRect(outerRectangle, paint); //paint.setcolor(color.transparent); // An obvIoUs color to help deBUGging paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); // A out B http://en.wikipedia.org/wiki/file:Alpha_compositing.svg float centerX = getWIDth() / 2; float centerY = getHeight() / 2; float radius = Math.min(getWIDth(), getHeight()) / 2 - 50; osCanvas.drawCircle(centerX, centerY, radius, paint); } @OverrIDe public boolean isInEditMode() { return true; } @OverrIDe protected voID onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); windowFrame = null; // If the layout changes null our frame so it can be recreated with the new wIDth and height }}
XML布局
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical"> <!--loading map in container--> <FrameLayout androID:ID="@+ID/container" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"/> <mypackage.RadiusOverlayVIEw androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_centerInParent="true" /></relativeLayout>
结果:
任何帮助将不胜感激.
解决方法:
您可以将VIEw.OntouchListener设置为RadiusOverlayVIEw并计算RadiusOverlayVIEw是否需要管理触摸事件.
在这个例子中,我通过测试RadiusOverlayVIEw颜色是否被触摸来计算这个!= 0(也许你想改进这个):
final RadiusOverlayVIEw radiusOverlayVIEw = (RadiusOverlayVIEw) findVIEwByID(R.ID.radiusVIEw);radiusOverlayVIEw.setontouchListener(new VIEw.OntouchListener() { @OverrIDe public boolean ontouch(final VIEw vIEw, final MotionEvent motionEvent) { vIEw.setDrawingCacheEnabled(true); Bitmap bmp = Bitmap.createBitmap(vIEw.getDrawingCache()); vIEw.setDrawingCacheEnabled(false); return bmp.getPixel((int) motionEvent.getX(), (int) motionEvent.getY()) != 0; }});
总结 以上是内存溢出为你收集整理的Android – CircleView内的Google地图全部内容,希望文章能够帮你解决Android – CircleView内的Google地图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)