[android] Anchoring was only set once while it was still unmeasured. There are times that a view is still unmeasured even after a measure call. We need to validate again before setting the offset. (#6154)

This commit is contained in:
Tobrun
2016-08-29 13:31:17 +02:00
committed by GitHub
parent ed431c925c
commit 7af5542226
2 changed files with 12 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.Projection;
@@ -115,14 +116,16 @@ public class MarkerViewManager {
final View convertView = markerViewMap.get(marker);
if (convertView != null) {
PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
if (marker.getOffsetX() == -1) {
if (marker.getOffsetX() == MapboxConstants.UNMEASURED) {
// ensure view is measured first
if (convertView.getMeasuredWidth() == 0) {
convertView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
}
int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth());
int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight());
marker.setOffset(x, y);
if (convertView.getMeasuredWidth() != 0) {
int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth());
int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight());
marker.setOffset(x, y);
}
}
convertView.setX(point.x - marker.getOffsetX());

View File

@@ -40,6 +40,11 @@ public class MapboxConstants {
*/
public final static boolean DEFAULT_SET_STORAGE_EXTERNAL = false;
/**
* Unmeasured state
*/
public final static float UNMEASURED = -1f;
/**
* Default animation time
*/