我希望能够添加一个"兴趣点"在位图上,可以点击谷歌地图图钉以显示信息。
我只需要知道如何将引脚添加到空间并将其保持在位图的右侧点(我可以平移和缩放位图)
抱歉,我是Android Studio的新手,并提前感谢! :)
答案 0 :(得分:0)
您可以在位图顶部绘制一个对象并实现一个触控回调,以验证您是否确实按下了标记。 这是一个简单的例子:
<com.myproject.RedImageView
android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:background="@android:color/holo_red_dark" />
package com.myproject;
public class RedImageView extends View {
private Paint mPaint;
private Rect mRect;
public RedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
//Draw a small white rectangle on top of our red ImageView
private void init() {
mPaint = new Paint();
mPaint.setColor(Color.WHITE);
mRect = new Rect(20, 20, 120, 120);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(mRect, mPaint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//Simple touch gesture has started
if (event.getAction() == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
//Match touch coordinates vs "Point of Interest" aka small white rectangle
if (mRect.contains(x, y)) {
Snackbar.make(this, "Clicked white", Snackbar.LENGTH_SHORT).show();
}
}
return super.onTouchEvent(event);
}
}