Code Monkey home page Code Monkey logo

shapedrawable's Introduction

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.2'
}

框架文档

  • 通用属性
// 设置 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)

框架亮点

  • 相比系统提供的 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.

shapedrawable's People

Contributors

getactivity avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

shapedrawable's Issues

请严格按照 issue 模板来提问题,否则一律不受理

最近发现有很多人给我提 issue 没有认真按照模板上面的来填写,导致了在排查问题的过程中浪费了作者许多不必要的时间和精力,所以请后面提 issue 的人务必严格遵守,否则我不会受理,直接关闭 issue。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.