tags:

views:

15

answers:

0

Hi all,

I need to have a drawable which is basically a triangle (or any polygon of choice), within this triangle i need to show an image exactly fitting the boundaries of the triangle.

Can anyone please tell me how to go about it

I have a basic draw code below

public class Square extends Drawable { private final Paint mPaint; private final RectF mRect;

public Square()
{
    mPaint = new Paint();
    mRect = new RectF();
}

@Override
public void draw(Canvas canvas)
{
    // Set the correct values in the Paint
    mPaint.setARGB(255, 255, 0, 0);
    mPaint.setStrokeWidth(2);
    mPaint.setStyle(Style.FILL);

    // Adjust the rect
    mRect.left = 15.0f;
    mRect.top = 50.0f;
    mRect.right = 55.0f;
    mRect.bottom = 75.0f;

    // Draw it
    canvas.drawRoundRect(mRect, 0.5f, 0.5f, mPaint);
}

@Override
public int getOpacity()
{
    return PixelFormat.OPAQUE;
}

@Override
public void setAlpha(int arg0)
{
}

@Override
public void setColorFilter(ColorFilter arg0)
{
}

}