Skip to content

getActivity/ShapeDrawable

Repository files navigation

ShapeDrawable 框架

集成步骤

  • 如果你的项目 Gradle 配置是在 7.0 以下,需要在 build.gradle 文件中加入
allprojects{repositories{// JitPack 远程仓库:https://jitpack.io maven{url 'https://jitpack.io' } } }
  • 如果你的 Gradle 配置是 7.0 及以上,则需要在 settings.gradle 文件中加入
dependencyResolutionManagement{repositories{// JitPack 远程仓库:https://jitpack.io maven{url 'https://jitpack.io' } } }
  • 配置完远程仓库后,在项目 app 模块下的 build.gradle 文件中加入远程依赖
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(@ShapeTypeLimitintshape) // 设置 Shape 宽度setWidth(intwidth) // 设置 Shape 高度setHeight(intheight) // 设置矩形的圆角大小setRadius(floatradius) setRadius(floattopLeftRadius, floattopRightRadius, floatbottomLeftRadius, floatbottomRightRadius)
  • 填充色相关
// 设置填充色setSolidColor(@ColorIntintstartColor, @ColorInt int endColor) setSolidColor(@ColorInt int startColor, @ColorInt int centerColor, @ColorInt int endColor) setSolidColor(@ColorInt int... colors) // 设置填充色渐变类型setSolidGradientType(@ShapeGradientTypeLimit int type) // 设置填充色渐变方向setSolidGradientOrientation(ShapeGradientOrientationorientation) // 设置填充色渐变中心 X 点坐标的相对位置(默认值为 0.5)setSolidGradientCenterX(float centerX) // 设置填充色渐变中心 Y 点坐标的相对位置(默认值为 0.5)setSolidGradientCenterY(float centerY) // 设置填充色渐变半径大小setSolidGradientRadius(float radius)
  • 边框色相关
// 设置边框色setStrokeColor(@ColorIntintstartColor, @ColorInt int endColor) setStrokeColor(@ColorInt int startColor, @ColorInt int centerColor, @ColorInt int endColor) setStrokeColor(@ColorInt int... colors) // 设置边框色渐变方向setStrokeGradientOrientation(ShapeGradientOrientationorientation) // 设置边框大小setStrokeSize(int size) // 设置边框每一节虚线宽度setStrokeDashSize(float dashSize) // 设置边框虚线每一节间隔setStrokeDashGap(float dashGap)
  • 阴影相关
// 设置阴影颜色setShadowColor(@ColorIntintcolor) // 设置阴影大小setShadowSize(intsize) // 设置阴影水平偏移setShadowOffsetX(intoffsetX) // 设置阴影垂直偏移setShadowOffsetY(intoffsetY)
  • 圆环相关
// 设置内环的半径大小setRingInnerRadiusSize(intsize) // 设置内环的半径比率setRingInnerRadiusRatio(floatratio) // 设置外环的厚度大小setRingThicknessSize(intsize) // 设置外环的厚度比率setRingThicknessRatio(floatratio)
  • 线条相关
// 设置线条重心setLineGravity(intlineGravity)
  • 其他的
// 将当前 Drawable 对象应用到 View 背景,需要调用此 API 设置到 View 背景,否则可能会导致虚线或者阴影无法生效intoBackground(Viewview)

框架亮点

  • 相比系统提供的 GradientDrawable 更强大,ShapeDrawable 支持设置阴影(颜色、大小、偏移量)

  • 相比系统提供的 GradientDrawable 更强大,ShapeDrawable 支持单独给边框设置渐变色(渐变色色值、渐变色方向)

  • 相比系统提供的 GradientDrawable 更强大,ShapeDrawable 支持单独给线条设置方向(top、bottom、left、right、start、end 方向都支持)

作者的其他开源项目

微信公众号:Android轮子哥

Android 技术 Q 群:10047167

如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 🐵就太👍了。您的支持将鼓励我继续创作: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. 

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages