Quatja/Vorolay
关于
VoronoiView 是一种 View(ViewGroup),可让你在 Voronoi 图的区域内添加并显示视图。
设计与媒体实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Vorolay
Vorolay is an Android ViewGroup that clips each child view to a cell of a Voronoi diagram. The library has no runtime dependencies and declares a minimum SDK of 17 (Android 4.2).

Install from source
With JDK 17 and Android SDK Platform 36 installed, publish the library to your local Maven repository from the Vorolay checkout. On Windows, use ./gradlew.bat in place of ./gradlew.
./gradlew :vorolay:publishReleasePublicationToMavenLocal
In your app project's settings.gradle.kts, add mavenLocal() to dependencyResolutionManagement.repositories. The content filter limits lookup in this repository to Vorolay.
dependencyResolutionManagement {
repositories {
mavenLocal {
content { includeModule("com.github.Quatja", "vorolay") }
}
google()
mavenCentral()
}
}
Add the dependency to your app module's build.gradle.kts.
dependencies {
implementation("com.github.Quatja:vorolay:1.1.0")
}
To build the library with your app, include the vorolay directory as a Gradle module named :vorolay, declare the com.android.library plugin in your root build, and use implementation(project(":vorolay")).
Quick start
Put VoronoiView in your activity layout.
<quatja.com.vorolay.VoronoiView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/voronoi"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:border_color="#FFFFFF"
app:generation_type="ordered" />
After loading the layout in your activity, add one child for each cell.
VoronoiView voronoi = findViewById(R.id.voronoi);
int[] colors = {0xFF90CAF9, 0xFFA5D6A7, 0xFFFFCC80};
for (int color : colors) {
View child = new View(this);
child.setBackgroundColor(color);
voronoi.addView(child, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
On API 17, call voronoi.setHardwareAccelerationEnabled(false) to use software rendering for clipping. Hardware-accelerated Canvas.clipPath() is available from API 18. Android hardware acceleration support
The diagram updates when the child list or content size changes. A child marked INVISIBLE still occupies a cell. Children marked GONE are skipped. Call refresh() to regenerate the diagram at the next layout pass.
Use setOnRegionClickListener to receive the child view and its index in the ViewGroup when the parent handles a tap. Clickable children can handle their own taps.
Customize the diagram
Set app:generation_type to random (the default), ordered to place points in a grid, or custom to supply your own points. In Java, use setGenerationType with GENERATION_TYPE_RANDOM, GENERATION_TYPE_ORDERED, or GENERATION_TYPE_CUSTOM.
| XML attribute | Java method | Effect |
|---|---|---|
app:show_border |
enableBorders |
Shows the cell borders. |
app:border_color |
setBorderColor |
Sets the border color. Pass an Android color integer in Java. |
app:border_width |
setBorderWidth |
Sets the width in pixels. |
app:border_round |
enableBorderRoundCorners |
Rounds the border corners. |
Custom points
The points map to children in order, skipping children marked GONE. Provide one distinct point per participating child. Coordinates are relative to the content area inside the view's padding.
For the three children in the quick start, change app:generation_type to custom, add app:custom_points="@array/voronoi_points" to the view, and save this resource in res/values/voronoi_points.xml.
<resources>
<string-array name="voronoi_points">
<item>0.25, 0.25</item>
<item>0.75, 0.25</item>
<item>0.50, 0.75</item>
</string-array>
</resources>
Each XML entry is an x, y pair from 0 to 1, inclusive. These coordinates scale with the content area. Malformed entries and coordinates outside that range are rejected when the view is inflated.
In Java, call setCustomPoints(List<VoronoiPoint>) with pixel coordinates and select GENERATION_TYPE_CUSTOM before the next layout. The method replaces any points supplied in XML. A mismatched count, duplicate points, or coordinates outside the content bounds cause an IllegalArgumentException during layout. See the Java example in the demo app.
License
Vorolay is licensed under the Apache License 2.0. The AAR includes the third-party license and attribution notices.
探索相关项目
加载中…