NinePatchpublic class NinePatch extends Object The NinePatch class permits drawing a bitmap in nine sections.
The four corners are unscaled; the four edges are scaled in one axis,
and the middle is scaled in both axes. Normally, the middle is
transparent so that the patch can provide a selection about a rectangle.
Essentially, it allows the creation of custom graphics that will scale the
way that you define, when content added within the image exceeds the normal
bounds of the graphic. For a thorough explanation of a NinePatch image,
read the discussion in the
2D
Graphics document.
The Draw 9-Patch
tool offers an extremely handy way to create your NinePatch images,
using a WYSIWYG graphics editor.
|
Fields Summary |
---|
private final Rect | mRect | private final Bitmap | mBitmap | private final byte[] | mChunk | private Paint | mPaint | private String | mSrcName |
Constructors Summary |
---|
public NinePatch(Bitmap bitmap, byte[] chunk, String srcName)Create a drawable projection from a bitmap to nine patches.
mBitmap = bitmap;
mChunk = chunk;
mSrcName = srcName;
validateNinePatchChunk(mBitmap.ni(), chunk);
| public NinePatch(NinePatch patch)
mBitmap = patch.mBitmap;
mChunk = patch.mChunk;
mSrcName = patch.mSrcName;
mPaint = new Paint(patch.mPaint);
validateNinePatchChunk(mBitmap.ni(), mChunk);
|
Methods Summary |
---|
public void | draw(Canvas canvas, RectF location)Draw a bitmap to nine patches.
nativeDraw(canvas.mNativeCanvas, location,
mBitmap.ni(), mChunk,
mPaint != null ? mPaint.mNativePaint : 0);
| public void | draw(Canvas canvas, Rect location)Draw a bitmap to nine patches.
nativeDraw(canvas.mNativeCanvas, location,
mBitmap.ni(), mChunk,
mPaint != null ? mPaint.mNativePaint : 0);
| public void | draw(Canvas canvas, Rect location, Paint paint)Draw a bitmap to nine patches.
nativeDraw(canvas.mNativeCanvas, location,
mBitmap.ni(), mChunk, paint != null ? paint.mNativePaint : 0);
| public int | getHeight()
return mBitmap.getHeight();
| public final Region | getTransparentRegion(Rect location)
int r = nativeGetTransparentRegion(mBitmap.ni(), mChunk, location);
return r != 0 ? new Region(r) : null;
| public int | getWidth()
return mBitmap.getWidth();
| public final boolean | hasAlpha()
return mBitmap.hasAlpha();
| public static native boolean | isNinePatchChunk(byte[] chunk)
| private static native void | nativeDraw(int canvas_instance, RectF loc, int bitmap_instance, byte[] c, int paint_instance_or_null)
| private static native void | nativeDraw(int canvas_instance, Rect loc, int bitmap_instance, byte[] c, int paint_instance_or_null)
| private static native int | nativeGetTransparentRegion(int bitmap, byte[] chunk, Rect location)
| public void | setPaint(Paint p)
mPaint = p;
| private static native void | validateNinePatchChunk(int bitmap, byte[] chunk)
|
|