Home

Awesome

ShapeDrawable 框架

集成步骤

allprojects {
    repositories {
        // JitPack 远程仓库:https://jitpack.io
        maven { url 'https://jitpack.io' }
    }
}
dependencyResolutionManagement {
    repositories {
        // JitPack 远程仓库:https://jitpack.io
        maven { url 'https://jitpack.io' }
    }
}
android {
    // 支持 JDK 1.8
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    // ShapeDrawable:https://github.com/getActivity/ShapeDrawable
    implementation 'com.github.getActivity:ShapeDrawable:3.3'
}

框架文档

// 设置 Shape 形状
setType(@ShapeTypeLimit int shape)

// 设置 Shape 宽度
setWidth(int width)

// 设置 Shape 高度
setHeight(int height)

// 设置矩形的圆角大小
setRadius(float radius)
setRadius(float topLeftRadius, float topRightRadius, float bottomLeftRadius, float bottomRightRadius)
// 设置填充色
setSolidColor(@ColorInt int startColor, @ColorInt int endColor)
setSolidColor(@ColorInt int startColor, @ColorInt int centerColor, @ColorInt int endColor)
setSolidColor(@ColorInt int... colors)

// 设置填充色渐变类型
setSolidGradientType(@ShapeGradientTypeLimit int type)

// 设置填充色渐变方向
setSolidGradientOrientation(ShapeGradientOrientation orientation)

// 设置填充色渐变中心 X 点坐标的相对位置(默认值为 0.5)
setSolidGradientCenterX(float centerX)
// 设置填充色渐变中心 Y 点坐标的相对位置(默认值为 0.5)
setSolidGradientCenterY(float centerY)

// 设置填充色渐变半径大小
setSolidGradientRadius(float radius)
// 设置边框色
setStrokeColor(@ColorInt int startColor, @ColorInt int endColor)
setStrokeColor(@ColorInt int startColor, @ColorInt int centerColor, @ColorInt int endColor)
setStrokeColor(@ColorInt int... colors)

// 设置边框色渐变方向
setStrokeGradientOrientation(ShapeGradientOrientation orientation)

// 设置边框大小
setStrokeSize(int size)

// 设置边框每一节虚线宽度
setStrokeDashSize(float dashSize)
// 设置边框虚线每一节间隔
setStrokeDashGap(float dashGap)
// 设置阴影颜色
setShadowColor(@ColorInt int color)

// 设置阴影大小
setShadowSize(int size)

// 设置阴影水平偏移
setShadowOffsetX(int offsetX)

// 设置阴影垂直偏移
setShadowOffsetY(int offsetY)
// 设置内环的半径大小
setRingInnerRadiusSize(int size)
// 设置内环的半径比率
setRingInnerRadiusRatio(float ratio)

// 设置外环的厚度大小
setRingThicknessSize(int size)
// 设置外环的厚度比率
setRingThicknessRatio(float ratio)
// 设置线条重心
setLineGravity(int lineGravity)
// 将当前 Drawable 对象应用到 View 背景,需要调用此 API 设置到 View 背景,否则可能会导致虚线或者阴影无法生效
intoBackground(View view)

框架亮点

作者的其他开源项目

微信公众号:Android轮子哥

Android 技术 Q 群:10047167

如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:

点击查看捐赠列表

License

Copyright 2023 Huang JinQun

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.