- Convert a BitmapDrawable into NinePatchDrawable at runtime.
- Just like iOS
ResizableImageWithCapInsets
method.
Before | After |
---|---|
- Kotlin
//Stretch from the middle
val capInsets = Rect(bitmapWidth / 2, bitmapHeight / 2, bitmapWidth / 2, bitmapHeight / 2)
val drawable = bitmapDrawable.resizableImageWithCapInsets(capInsets)
imageView.setImageDrawable(drawable)
- Java
//Stretch from the middle
Rect capInsets = new Rect(bitmapWidth / 2, bitmapHeight / 2, bitmapWidth / 2, bitmapHeight / 2);
NinePatchDrawable drawable = NinePatchGenerator.resizableImageWithCapInsets(bitmapDrawable, capInsets);
imageView.setImageDrawable(drawable);
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.YvesCheung:NinePatchChunk:x.y.z'
}