मुझे कॉमन्सवेयर ड्रैग और ड्रॉप के शानदार कार्य के लिए थोड़ा ऑप्टिमाइज़ेशन मिला।
मैं अपने मानचित्र पर मार्करों के साथ कुछ सटीक मेशरमेंट कर रहा था, और मैं चाहता था कि मेरा मार्कर उस स्थान पर बिल्कुल सही हो जो मैंने स्पर्श किया और मेरी उंगली को उठा लिया ताकि मैशरमेंट बिल्कुल सटीक हो।
कॉमन्सवेयर से मूल पर यदि आप मार्कर के "पास" को स्पर्श करते हैं, तो मार्कर उस सटीक बिंदु पर नहीं जाता है, लेकिन आपकी उंगली के आंदोलन के साथ चलता है। मुझे मार्कर को ACTION_DOWN, ACTION_MOVE और ACTION_UP पर मेरी अंगुली के ठीक नीचे दिखाई देने की आवश्यकता थी।
अगर किसी को इसकी आवश्यकता है तो कोड यहां दिया गया है। मुझे इस समारोह को बनाने के लिए कॉमन्सवेयर का शुक्रिया अदा करना है, यह वास्तव में एक अच्छा विचार है।
यह संशोधित कोड का हिस्सा है।
मेरा मानचित्र दृश्य नक्शा है;
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
final int action=event.getAction();
final int x=(int)event.getX();
final int y=(int)event.getY();
boolean result=false;
if (action==MotionEvent.ACTION_DOWN) {
for (OverlayItem item : mOverlays) {
Point p=new Point(0,0);
mapa.getProjection().toPixels(item.getPoint(), p);
//I maintain the hitTest's bounds so you can still
//press near the marker
if (hitTest(item, marker, x-p.x, y-p.y)) {
result=true;
inDrag=item;
mOverlays.remove(inDrag);
populate();
//Instead of using the DragImageOffSet and DragTouchOffSet
//I use the x and y coordenates from the Point
setDragImagePosition(x, y);
dragImage.setVisibility(View.VISIBLE);
break;
}
}
}
else if (action==MotionEvent.ACTION_MOVE && inDrag!=null) {
setDragImagePosition(x, y);
result=true;
}
else if (action==MotionEvent.ACTION_UP && inDrag!=null) {
dragImage.setVisibility(View.GONE);
//I get the geopoint without using any OffSet, directly with the
//Point coordenates
GeoPoint pt=mapa.getProjection().fromPixels(x,y);
OverlayItem toDrop=new OverlayItem(pt, inDrag.getTitle(),
inDrag.getSnippet());
orig = inDrag.getMarker(0);
//In my case I had down heading Arrows as markers, so I wanted my
//bounds to be at the center bottom
toDrop.setMarker(boundCenterBottom(orig));
mOverlays.add(toDrop);
populate();
inDrag=null;
result=true;
}
return(result || super.onTouchEvent(event, mapView));
}
private void setDragImagePosition(int x, int y) {
RelativeLayout.LayoutParams lp=
(RelativeLayout.LayoutParams)dragImage.getLayoutParams();
//Instead of using OffSet I use the Point coordenates.
//I want my arrow to appear pointing to the point I am moving, so
//I set the margins as the Point coordenates minus the Height and half the
//width of my arrow.
lp.setMargins(x-(dragImage.getWidth()/2),y-dragImage.getHeight(), 0, 0);
dragImage.setLayoutParams(lp);
}
इसके साथ आप अपने तीर को जहां आप अपने साथ दबाते हैं, वहां से तीर की जगह से आगे बढ़ते हुए दिखाई देते हैं।
लिंक और स्पष्टीकरण के लिए बहुत बहुत धन्यवाद! मैं एंड्रॉइड के लिए नया हूं, इसलिए मेरे लिए एक अच्छी तरह से काम करने वाली परियोजना की संरचना को देखना अच्छा है, यह जानने के लिए कि चीजों को वास्तविक कैसे किया जाए और न केवल वहां चीजें फेंक दें। धन्यवाद। – kakka47
Thnx आदमी, यह वास्तव में मदद की – binW
मुझे लगता है कि यह पुराना उत्तर अब है। bcoz v2 dosenot समर्थन ओवरले। क्या आपके पास V2 के लिए कुछ भी है –