我想将标记放在像Google地图这样的图像上,具有缩放,滚动图像,动态添加图像标记和标记拖动等功能。放在图像上。
当图像变焦时,标记无法从该位置移动。 在标记单击时,将打开对话框以显示其信息
另外,我想要在图像上标记的x,y位置,以便下次我可以将标记直接放到该位置。
这是我的xml:
<ScrollView
android:id="@+id/imageOuterScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<HorizontalScrollView
android:id="@+id/ImageHorizontalScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/markerAndLoadedImageView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/loadedImageFromServer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
</com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView>
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
Java代码:
private void addNewMarker(@DrawableRes int resid, float xCoordinates, float yCoordinates, String pinID) {
image = new ImageView(getActivity());
image.setBackgroundResource(resid);
markerAndLoadedImageView.addView(image);
image.setX(xCoordinates);
image.setY(yCoordinates);
}
private View.OnTouchListener onTouchListener() {
return new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View view, MotionEvent event) {
mSitePlanImageHorizontalScrollView.requestDisallowInterceptTouchEvent(true);
mSitePlanImageOuterScrollView.requestDisallowInterceptTouchEvent(true);
final int x = (int) event.getRawX();
final int y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams)
view.getLayoutParams();
xDelta = x - lParams.leftMargin;
yDelta = y - lParams.topMargin;
pressStartTime = System.currentTimeMillis();
pressedX = event.getX();
pressedY = event.getY();
break;
case MotionEvent.ACTION_UP:
long pressDuration = System.currentTimeMillis() - pressStartTime;
Utility.printLog("pressDuration", "pressDuration" + pressDuration);
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view
.getLayoutParams();
layoutParams.leftMargin = x - xDelta;
layoutParams.topMargin = y - yDelta;
layoutParams.rightMargin = 0;
layoutParams.bottomMargin = 0;
view.setLayoutParams(layoutParams);
break;
}
Utility.printLog("POINTS", "POINTS : X:" + String.valueOf(x));
Utility.printLog("POINTS", "POINTS : Y:" + String.valueOf(y));
XPoint = x;
YPoint = y;
mMainParentProjectListLayout.invalidate();
return true;
}
};
}
我使用下面的库进行缩放:
https://github.com/davemorrissey/subsampling-scale-image-view
我可以在图像上放置标记,但是我没有在图像上获得标记的确切位置,因此我将标记放在该特定位置。 此外,标记点击和拖动&amp;丢弃功能根据需要不平滑。
任何人都可以帮助我,提前谢谢。
对不起英语:)