# co.revely.gradient **Repository Path**: ouyangpengdev/co.revely.gradient ## Basic Information - **Project Name**: co.revely.gradient - **Description**: An Android library for easy gradient management - **Primary Language**: Kotlin - **License**: WTFPL - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-03-23 - **Last Updated**: 2021-03-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README RevelyGradient ======== [ ![Download](https://api.bintray.com/packages/revely/maven/RevelyGradient/images/download.svg) ](https://bintray.com/revely/maven/RevelyGradient/_latestVersion) RevelyGradient is an Android library for easy gradient management ! About Revely ======== ### [](https://www.revely.co/) [Web site](https://www.revely.co/) - [](https://gitlab.com/revely) [Open Source projects](https://gitlab.com/revely) - [](https://www.patreon.com/revely_inc) [Become my Patreon](https://www.patreon.com/revely_inc) - [](https://twitter.com/revely_inc) [Twitter](https://twitter.com/revely_inc) - [](https://www.instagram.com/revely_inc/) [Instagram](https://www.instagram.com/revely_inc/) - [](https://www.behance.net/revely_inc) [Behance](https://www.behance.net/revely_inc) Installation ======== Add the dependency ```groovy dependencies { compile 'co.revely:gradient:1.0.1' } ``` Usage ======== Kotlin ```java RevelyGradient .linear() .colors(intArrayOf(Color.parseColor("#FF2525"), Color.parseColor("#6078EA"))) .onBackgroundOf(view) ``` Java ```java RevelyGradient .linear() .colors(new int[] {Color.parseColor("#FF2525"), Color.parseColor("#6078EA")}) .onBackgroundOf(findViewById(R.id.view)); ``` ![demo_1](https://gitlab.com/revely/assets/raw/master/revely_gradient/background_gradient.gif) ![demo_2](https://gitlab.com/revely/assets/raw/master/revely_gradient/text_gradient.png) Choose the type of your gradient ```java .radial() .linear() .sweep() ``` Choose the gradient colors ```java .colors(intArrayOf(Color.parseColor("#FF2525"), Color.parseColor("#6078EA"), Color.parseColor("#6078EA"))) ``` Center your gradient ```java .center(100f, 200f) ``` Rotate the gradient around the center ```java .angle(42) ``` Change the transparency of your gradient ```java .alpha(0.5f) ``` Scale the gradient ```java .scale(0.5f, 1f) ``` Change the positions of color in the gradient ```java .offsets(floatArrayOf(0f, 0.1f, 0.5f, 1f)) ``` Apply the gradient on the background of view ```java .onBackgroundOf(text_view) ``` or directly on the view (TextView, ImageView, Button, ...) ```java .on(text_view) ``` You can also use the layer function to stack several gradients ```java .layer( RevelyGradient .radial(TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 150f, Resources.getSystem().displayMetrics )) .colors(intArrayOf(Color.parseColor("#ffdd55"), Color.parseColor("#ffdd55"), Color.parseColor("#ff543e"), Color.parseColor("#c837ab"))) .offsets(floatArrayOf(0f, 0.1f, 0.5f, 1f)) .center(50, 400), RevelyGradient .radial(TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 170f, Resources.getSystem().displayMetrics )) .colors(intArrayOf(Color.parseColor("#3771c8"), Color.parseColor("#3771c8"), Color.parseColor("#006600ff"))) .offsets(floatArrayOf(0f, 0.128f, 1f)) .angle(-15f) .scale(1f, 0.4f) .center(0, 0) ).onBackgroundOf(view) ``` To animate your gradient use `.animate()` ```java val color1 = Color.parseColor("#00c6ff") val color2 = Color.parseColor("#ff72ff") val valueAnimator = ValueAnimator.ofFloat(0f, 360f) valueAnimator.duration = 15000 valueAnimator.repeatCount = ValueAnimator.INFINITE valueAnimator.interpolator = LinearInterpolator() RevelyGradient.sweep() .colors(intArrayOf(color1, color2, color1)) .animate(valueAnimator, { _valueAnimator, _gradientDrawable -> _gradientDrawable.angle = _valueAnimator.animatedValue as Float }) .onBackgroundOf(container) valueAnimator.start() ```