Home Ask Login Register

Developers Planet

Your answer is one click away!

AK2016 February 2016

PinView does not draw in Loop

I have extended SubsamplingScaleImageView to create PinView as recommend in documentation. I am able to draw Pint at proper location. But issue i am facing is : When i try to draw in loop it, Pin goes missing. I verified OnDraw is called on Main Thread.

Following is code i am using

public class PinView extends SubsamplingScaleImageView {

private PointF sPin;
private Bitmap pin;
private PointF sBlueDot;
private Bitmap blueDot;

public PinView(Context context) {
    this(context, null);

public PinView(Context context, AttributeSet attr) {

public void setPin(PointF sPin) {
    this.sPin = sPin;
public void setBlueDot(PointF sPin) {
    this.sBlueDot = sPin;
public PointF getPin() {
    return sPin;

private void initialise() {
    float density = getResources().getDisplayMetrics().densityDpi;
    pin = BitmapFactory.decodeResource(this.getResources(), drawable.pushpin_blue);
    float w = (density/420f) * pin.getWidth();
    float h = (density/420f) * pin.getHeight();
    pin = Bitmap.createScaledBitmap(pin, (int)w, (int)h, true);
private void initialiseBlueDot() {
    float density = getResources().getDisplayMetrics().densityDpi;
    blueDot = BitmapFactory.decodeResource(this.getResources(), drawable.pushpin_blue);
    float w = (density/420f) * blueDot.getWidth();
    float h = (density/420f) * blueDot.getHeight();
    blueDot = Bitmap.createScaledBitmap(blueDot, (int)w, (int)h, true);

protected void onDraw(Canvas canvas) {

    // Don't draw pin before image is ready so it doesn't move around during setup.
    if (!isReady()) {

    Paint paint = new Paint();

    if (sPin != null && pin != null) {
        PointF vPin = sourceToViewCoord(sPin);
        float vX = vPin.x - (pin        


AK2016 February 2016

I got it fixed myself. Issue was with XY and source xy points. used viewToSourceCoord() to get proper location points.

Post Status

Asked in February 2016
Viewed 3,606 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life