• Stars
    star
    339
  • Rank 124,632 (Top 3 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vector 9-patches for Android.

v9

v9 Android build status

v9 is an Android library that provides the ability to dynamically resize Path objects as you would 9-patch bitmaps. In the example below, the chat bubble is dynamically resized while preserving the corners:

v9-demo.mov

Each slice of the original path (indicated by the shaded areas in the example above) defines a horizontal or vertical region of the path that needs to be stretched. A path can be resized using multiple slices:

Screen.Recording.2022-08-26.at.2.42.35.PM.mov

When multiple slices are used, the amount of stretch applied is proportional to the size of each slice. This behavior is used in the example above to keep the dark bars centered vertically and to spaced them equally horizontally, thus properly preserving details inside the path.

v9 is compatible with API 21+.

Maven

repositories {
    // ...
    mavenCentral()
}

dependencies {
    implementation 'dev.romainguy:v9:0.2.0'
}

How to use

Slicing a Path gives you a PathResizer. The easiest way to slice is to use a single vertical and a single horizontal slice:

val pathResizer = path.slice(Slices(9.0f, 7.0f, 15.0f, 13.0f))

This syntax follows the rectangle convention on Android of passing the top, left, right, and bottom coordinates: there's a vertical slice from 9.0 to 15.0 and a horizontal slice from 7.0 to 13.0.

You can also explicitly declare a list of slices:

val pathResizer = path.slice(
    Slices(
        listOf(Slice(9.0f, 10.0f), Slice(14.0f, 15.0f)),
        listOf(Slice(5.0f, 6.0f),  Slice(18.0f, 19.0f))
    )
)

Once you have a PathResizer, you can call the resize() method to create a new path derived from the original, at the desired size:

val resizedPath = pathResizer.resize(width, height)

For performance considerations, you can pass an existing path to resize(). This path will be rewound and returned:

val resizedPath = pathResizer.resize(width, height, destinationpath)
// resizedPath === destinationpath

License

Please see LICENSE.

More Repositories

1

ViewServer

Local server for Android's HierarchyViewer
Java
2,495
star
2

road-trip

A sample Android application that demonstrates how to implement various visual effects.
Java
1,463
star
3

google-io-2014

Demo for the Material Witness talk I gave at Google I/O.
Java
1,253
star
4

kotlin-math

Set of Kotlin APIs to make graphics math easier to write.
Kotlin
849
star
5

elegant-underline-android

Exploring possible implementations for better underline text decoration on Android
Java
818
star
6

kotlin-explorer

Desktop tool to quickly explore disassembled Kotlin code.
Kotlin
759
star
7

combo-breaker

Text layout for Compose to flow text around arbitrary shapes.
Kotlin
577
star
8

sample-materials-shop

Sample app for Jetpack Compose Developer Preview 2
Kotlin
497
star
9

pathway

A set of APIs to manipulate graphics paths on Android.
Kotlin
199
star
10

sample-wake-me-up

Sample app demonstrating interop between Jetpack Compose and the Android UI toolkit, including SurfaceView
Kotlin
193
star
11

filthy-rich-clients

Samples for the book Filthy Rich Clients
Java
154
star
12

experiment-apex

A basic, incomplete, buggy, far from efficient UI toolkit for Kotlin/Android. An experiment for fun and to learn.
Kotlin
87
star
13

elegant-underline-keynote

A command line utility to generate fancier underlines for Apple Keynote
Swift
60
star
14

markdeep-rasterizer

Converts Markdeep (https://casual-effects.com/markdeep/) files to static HTML.
JavaScript
33
star
15

jext

Source code editor
Java
20
star
16

homebrew-gfx

Custom formulaes for HomeBrew, designed for graphics work
Ruby
2
star