{"id":313957,"date":"2020-11-28T15:00:41","date_gmt":"2020-11-28T15:00:41","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=313957"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=313957","title":{"rendered":"\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0446\u0432\u0435\u0442\u043d\u044b\u0435 \u0442\u0435\u043d\u0438 \u0432 Android \u0441 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u043c \u0438 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0435\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0430 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u043c\u0430\u043a\u0431\u0443\u043a\u043e\u0432 \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u043b \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/be9\/1ba\/bf3\/be91babf3d5a1c95cf755c54ae5c3d50.png\" width=\"462\" height=\"464\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0435\u0440\u0435\u043b\u0438\u0432\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0446\u0432\u0435\u0442\u043d\u044b\u0435 \u0442\u0435\u043d\u0438 \u043d\u0430 \u0442\u0435\u043c\u043d\u043e\u043c \u0444\u043e\u043d\u0435, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043b\u0430\u0441\u0441\u043d\u043e. <\/p>\n<p>\u0412\u043e\u0442 \u0434\u043e\u0448\u043b\u0438 \u0440\u0443\u043a\u0438, \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0430\u043d\u0434\u0440\u043e\u0438\u0434\u0435 \u0442\u0430\u043a \u0436\u0435. \u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4c2\/e0b\/a8f\/4c2e0ba8fc25d5f9bc0d5c4d29f1ce1f.gif\" width=\"480\" height=\"592\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u044e\u0441\u044c, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u0434\u043e api 28 \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u043d\u044b\u0445 elevation, \u043f\u043e\u0441\u043b\u0435 api 28 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0446\u0432\u0435\u0442\u043d\u044b\u0445 \u0442\u0435\u043d\u0435\u0439, \u043d\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c drawable, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0432\u0438\u0434\u0435 background \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c padding \u043d\u0430 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0432\u044c\u044e\u0445\u0435, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0431\u044b\u043b \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u043d\u0438.<\/p>\n<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f Drawable \u0441 \u0442\u0435\u043d\u044c\u044e:<\/p>\n<pre><code class=\"kotlin\">\/**  * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 drawable \u0441 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u043c-\u0442\u0435\u043d\u044c\u044e  *\/ private fun createShadowDrawable(     @ColorInt colors: IntArray,     cornerRadius: Float,     elevation: Float,     centerX: Float,     centerY: Float ): ShapeDrawable {      val shadowDrawable = ShapeDrawable()      \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0447\u0435\u0440\u043d\u0443\u044e \u0442\u0435\u043d\u044c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e     shadowDrawable.paint.setShadowLayer(         elevation, \/\/ \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0435\u043d\u0438         0f, \/\/ \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u0435\u043d\u0438 \u043f\u043e \u043e\u0441\u0438 \u0425         0f, \/\/ \u043f\u043e \u0423         Color.BLACK \/\/ \u0446\u0432\u0435\u0442 \u0442\u0435\u043d\u0438     )      \/**      * \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u043e\u043a\u0440\u0430\u0441\u043a\u0443 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u043c      *      * @param centerX - \u0426\u0435\u043d\u0442\u0440 SweepGradient \u043f\u043e \u043e\u0441\u0438 \u0425. \u0411\u0435\u0440\u0435\u043c \u0446\u0435\u043d\u0442\u0440 \u0432\u044c\u044e\u0445\u0438      * @param centerY - \u0426\u0435\u043d\u0442\u0440 \u043f\u043e \u043e\u0441\u0438 \u0423      * @param colors - \u0426\u0432\u0435\u0442\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0446\u0432\u0435\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u0435\u043d \u043f\u0435\u0440\u0432\u043e\u043c\u0443,      * \u0438\u043d\u0430\u0447\u0435 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430      * @param position - \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043e\u0442 0 \u0434\u043e 1.      * \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 null \u0442.\u043a. \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442      *\/     shadowDrawable.paint.shader = SweepGradient(         centerX,         centerY,         colors,         null     )      \/\/ \u0414\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043a\u0443\u0433\u043b\u0435\u043d\u0438\u0435 \u0443\u0433\u043b\u043e\u0432     val outerRadius = FloatArray(8) { cornerRadius }     shadowDrawable.shape = RoundRectShape(outerRadius, null, null)      return shadowDrawable }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u044d\u0442\u043e\u0433\u043e drawable \u0444\u043e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u0440\u0430\u0434\u0443\u0433\u0438 \u0442\u0435\u0445 \u0446\u0432\u0435\u0442\u043e\u0432, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0434\u043d\u043e\u0446\u0432\u0435\u0442\u043d\u044b\u0439 \u0444\u043e\u043d. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0442\u043e\u0440\u0443\u044e drawable:<\/p>\n<pre><code class=\"kotlin\">\/**  * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0446\u0432\u0435\u0442\u043d\u043e\u0433\u043e drawable \u0441 \u0437\u0430\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0443\u0433\u043b\u0430\u043c\u0438  * \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0432\u0435\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430  *\/ private fun createColorDrawable(     @ColorInt backgroundColor: Int,     cornerRadius: Float ) = GradientDrawable().apply {         setColor(backgroundColor)         setCornerRadius(cornerRadius)     }<\/code><\/pre>\n<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434\u0430 \u043d\u0430 \u0432\u044c\u044e\u0445\u0443-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440. \u0423 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 LayerDrawable \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u043b\u043e\u044f\u043c\u0438. 1 &#8212; \u0442\u0435\u043d\u044c, 2 &#8212; \u043f\u0440\u043e\u0441\u0442\u043e \u0446\u0432\u0435\u0442 \u0441 \u0437\u0430\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0443\u0433\u043b\u0430\u043c\u0438.<\/p>\n<pre><code class=\"kotlin\">\/**  * \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434 \u0441 \u0442\u0435\u043d\u044c\u044e \u043d\u0430 \u0432\u044c\u044e\u0445\u0443, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f padding  *\/ private fun View.setColorShadowBackground(     shadowDrawable: ShapeDrawable,     colorDrawable: Drawable,     padding: Int ) {     val drawable = LayerDrawable(arrayOf(shadowDrawable, colorDrawable))     drawable.setLayerInset(0, padding, padding, padding, padding)     drawable.setLayerInset(1, padding, padding, padding, padding)     setPadding(padding, padding, padding, padding)     background = drawable }<\/code><\/pre>\n<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 \u0432\u044c\u044e\u0445\u0435:<\/p>\n<pre><code class=\"kotlin\">\/\/ \u0436\u0434\u0435\u043c \u043a\u043e\u0433\u0434\u0430 \u0432\u044c\u044e\u0445\u0430 \u043e\u0442\u0440\u0438\u0441\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u0435\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u044b targetView.doOnNextLayout {     val colors = intArrayOf(         Color.WHITE,         Color.RED,         Color.WHITE     )     val cornerRadius = 16f.dp     val padding = 30.dp     val centerX = it.width.toFloat() \/ 2 - padding     val centerY = it.height.toFloat() \/ 2 - padding      val shadowDrawable = createShadowDrawable(         colors = colors,         cornerRadius = cornerRadius,         elevation = padding \/ 2f,         centerX = centerX,         centerY = centerY     )     val colorDrawable = createColorDrawable(         backgroundColor = Color.DKGRAY,         cornerRadius = cornerRadius     )      it.setColorShadowBackground(         shadowDrawable = shadowDrawable,         colorDrawable = colorDrawable,         padding = 30.dp     ) }<\/code><\/pre>\n<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0430\u043d\u0438\u043c\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0446\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435. \u0417\u0430\u0446\u0438\u043a\u043b\u0438\u043c.<\/p>\n<pre><code class=\"kotlin\">\/**  * \u0410\u043d\u0438\u043c\u0430\u0446\u0438\u044f drawable-\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430  *\/ private fun animateShadow(     shapeDrawable: ShapeDrawable,     @ColorInt startColors: IntArray,     @ColorInt endColors: IntArray,     duration: Long,     centerX: Float,     centerY: Float ) {     \/**      * \u041c\u0435\u043d\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 0f \u0434\u043e 1f \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f      * \u0446\u0432\u0435\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e [ColorUtils.blendARGB]      *\/     ValueAnimator.ofFloat(0f, 1f).apply {         \/\/ \u0417\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043f\u0435\u0440\u0435\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0442\u0435\u043d\u0438. \u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u0444\u043f\u0441 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438         val invalidateDelay = 100         var deltaTime = System.currentTimeMillis()          \/\/ \u041d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u044b\u043c\u0438 \u0446\u0432\u0435\u0442\u0430\u043c\u0438         val mixedColors = IntArray(startColors.size)          addUpdateListener { animation -&gt;             if (System.currentTimeMillis() - deltaTime &gt; invalidateDelay) {                 val animatedFraction = animation.animatedValue as Float                 deltaTime = System.currentTimeMillis()                  \/\/ \u0421\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u043c \u0446\u0432\u0435\u0442\u0430                 for (i in 0..mixedColors.lastIndex) {                     mixedColors[i] = ColorUtils.blendARGB(startColors[i], endColors[i], animatedFraction)                 }                  \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0442\u0435\u043d\u044c                 shapeDrawable.paint.shader = SweepGradient(                     centerX,                     centerY,                     mixedColors,                     null                 )                 shapeDrawable.invalidateSelf()             }         }         repeatMode = ValueAnimator.REVERSE         repeatCount = Animation.INFINITE         setDuration(duration)         start()     } }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c:<\/p>\n<pre><code class=\"kotlin\">\/\/ \u0412\u0442\u043e\u0440\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0446\u0432\u0435\u0442\u0430\u043c\u0438. \u0420\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439. val endColors = intArrayOf( \tColor.RED, \tColor.WHITE, \tColor.RED ) animateShadow( \tshapeDrawable = shadowDrawable,   startColors = colors,   endColors = endColors,   duration = 2000,   centerX = centerX,   centerY = centerY )<\/code><\/pre>\n<\/p>\n<p>\u0412\u0441\u0435. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043d\u043e\u043f\u043a\u043e\u0439, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c  ripple \u044d\u0444\u0444\u0435\u043a\u0442 \u0434\u043b\u044f foreground \u0432\u044c\u044e\u0445\u0438 \u0438 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043c \u043e\u0442\u0441\u0442\u0443\u043f, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0441 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0430\u0441\u044c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/530376\/\"> https:\/\/habr.com\/ru\/post\/530376\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0430 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u043c\u0430\u043a\u0431\u0443\u043a\u043e\u0432 \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u043b \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0435\u0440\u0435\u043b\u0438\u0432\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0446\u0432\u0435\u0442\u043d\u044b\u0435 \u0442\u0435\u043d\u0438 \u043d\u0430 \u0442\u0435\u043c\u043d\u043e\u043c \u0444\u043e\u043d\u0435, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043b\u0430\u0441\u0441\u043d\u043e. <\/p>\n<p>\u0412\u043e\u0442 \u0434\u043e\u0448\u043b\u0438 \u0440\u0443\u043a\u0438, \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0430\u043d\u0434\u0440\u043e\u0438\u0434\u0435 \u0442\u0430\u043a \u0436\u0435. \u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u044e\u0441\u044c, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u0434\u043e api 28 \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u043d\u044b\u0445 elevation, \u043f\u043e\u0441\u043b\u0435 api 28 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0446\u0432\u0435\u0442\u043d\u044b\u0445 \u0442\u0435\u043d\u0435\u0439, \u043d\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c drawable, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0432\u0438\u0434\u0435 background \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c padding \u043d\u0430 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0432\u044c\u044e\u0445\u0435, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0431\u044b\u043b \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u043d\u0438.<\/p>\n<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f Drawable \u0441 \u0442\u0435\u043d\u044c\u044e:<\/p>\n<pre><code class=\"kotlin\">\/**  * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 drawable \u0441 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u043c-\u0442\u0435\u043d\u044c\u044e  *\/ private fun createShadowDrawable(     @ColorInt colors: IntArray,     cornerRadius: Float,     elevation: Float,     centerX: Float,     centerY: Float ): ShapeDrawable {      val shadowDrawable = ShapeDrawable()      \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0447\u0435\u0440\u043d\u0443\u044e \u0442\u0435\u043d\u044c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e     shadowDrawable.paint.setShadowLayer(         elevation, \/\/ \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0435\u043d\u0438         0f, \/\/ \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u0435\u043d\u0438 \u043f\u043e \u043e\u0441\u0438 \u0425         0f, \/\/ \u043f\u043e \u0423         Color.BLACK \/\/ \u0446\u0432\u0435\u0442 \u0442\u0435\u043d\u0438     )      \/**      * \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u043e\u043a\u0440\u0430\u0441\u043a\u0443 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u043c      *      * @param centerX - \u0426\u0435\u043d\u0442\u0440 SweepGradient \u043f\u043e \u043e\u0441\u0438 \u0425. \u0411\u0435\u0440\u0435\u043c \u0446\u0435\u043d\u0442\u0440 \u0432\u044c\u044e\u0445\u0438      * @param centerY - \u0426\u0435\u043d\u0442\u0440 \u043f\u043e \u043e\u0441\u0438 \u0423      * @param colors - \u0426\u0432\u0435\u0442\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0446\u0432\u0435\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u0435\u043d \u043f\u0435\u0440\u0432\u043e\u043c\u0443,      * \u0438\u043d\u0430\u0447\u0435 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430      * @param position - \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043e\u0442 0 \u0434\u043e 1.      * \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 null \u0442.\u043a. \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442      *\/     shadowDrawable.paint.shader = SweepGradient(         centerX,         centerY,         colors,         null     )      \/\/ \u0414\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043a\u0443\u0433\u043b\u0435\u043d\u0438\u0435 \u0443\u0433\u043b\u043e\u0432     val outerRadius = FloatArray(8) { cornerRadius }     shadowDrawable.shape = RoundRectShape(outerRadius, null, null)      return shadowDrawable }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u044d\u0442\u043e\u0433\u043e drawable \u0444\u043e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u0440\u0430\u0434\u0443\u0433\u0438 \u0442\u0435\u0445 \u0446\u0432\u0435\u0442\u043e\u0432, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445, \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0434\u043d\u043e\u0446\u0432\u0435\u0442\u043d\u044b\u0439 \u0444\u043e\u043d. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0442\u043e\u0440\u0443\u044e drawable:<\/p>\n<pre><code class=\"kotlin\">\/**  * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0446\u0432\u0435\u0442\u043d\u043e\u0433\u043e drawable \u0441 \u0437\u0430\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0443\u0433\u043b\u0430\u043c\u0438  * \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0432\u0435\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430  *\/ private fun createColorDrawable(     @ColorInt backgroundColor: Int,     cornerRadius: Float ) = GradientDrawable().apply {         setColor(backgroundColor)         setCornerRadius(cornerRadius)     }<\/code><\/pre>\n<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434\u0430 \u043d\u0430 \u0432\u044c\u044e\u0445\u0443-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440. \u0423 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 LayerDrawable \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u043b\u043e\u044f\u043c\u0438. 1 &#8212; \u0442\u0435\u043d\u044c, 2 &#8212; \u043f\u0440\u043e\u0441\u0442\u043e \u0446\u0432\u0435\u0442 \u0441 \u0437\u0430\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0443\u0433\u043b\u0430\u043c\u0438.<\/p>\n<pre><code class=\"kotlin\">\/**  * \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0431\u044d\u043a\u0433\u0440\u0430\u0443\u043d\u0434 \u0441 \u0442\u0435\u043d\u044c\u044e \u043d\u0430 \u0432\u044c\u044e\u0445\u0443, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f padding  *\/ private fun View.setColorShadowBackground(     shadowDrawable: ShapeDrawable,     colorDrawable: Drawable,     padding: Int ) {     val drawable = LayerDrawable(arrayOf(shadowDrawable, colorDrawable))     drawable.setLayerInset(0, padding, padding, padding, padding)     drawable.setLayerInset(1, padding, padding, padding, padding)     setPadding(padding, padding, padding, padding)     background = drawable }<\/code><\/pre>\n<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 \u0432\u044c\u044e\u0445\u0435:<\/p>\n<pre><code class=\"kotlin\">\/\/ \u0436\u0434\u0435\u043c \u043a\u043e\u0433\u0434\u0430 \u0432\u044c\u044e\u0445\u0430 \u043e\u0442\u0440\u0438\u0441\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u0435\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u044b targetView.doOnNextLayout {     val colors = intArrayOf(         Color.WHITE,         Color.RED,         Color.WHITE     )     val cornerRadius = 16f.dp     val padding = 30.dp     val centerX = it.width.toFloat() \/ 2 - padding     val centerY = it.height.toFloat() \/ 2 - padding      val shadowDrawable = createShadowDrawable(         colors = colors,         cornerRadius = cornerRadius,         elevation = padding \/ 2f,         centerX = centerX,         centerY = centerY     )     val colorDrawable = createColorDrawable(         backgroundColor = Color.DKGRAY,         cornerRadius = cornerRadius     )      it.setColorShadowBackground(         shadowDrawable = shadowDrawable,         colorDrawable = colorDrawable,         padding = 30.dp     ) }<\/code><\/pre>\n<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0430\u043d\u0438\u043c\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0446\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435. \u0417\u0430\u0446\u0438\u043a\u043b\u0438\u043c.<\/p>\n<pre><code class=\"kotlin\">\/**  * \u0410\u043d\u0438\u043c\u0430\u0446\u0438\u044f drawable-\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430  *\/ private fun animateShadow(     shapeDrawable: ShapeDrawable,     @ColorInt startColors: IntArray,     @ColorInt endColors: IntArray,     duration: Long,     centerX: Float,     centerY: Float ) {     \/**      * \u041c\u0435\u043d\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 0f \u0434\u043e 1f \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f      * \u0446\u0432\u0435\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e [ColorUtils.blendARGB]      *\/     ValueAnimator.ofFloat(0f, 1f).apply {         \/\/ \u0417\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043f\u0435\u0440\u0435\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0442\u0435\u043d\u0438. \u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u0444\u043f\u0441 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438         val invalidateDelay = 100         var deltaTime = System.currentTimeMillis()          \/\/ \u041d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u044b\u043c\u0438 \u0446\u0432\u0435\u0442\u0430\u043c\u0438         val mixedColors = IntArray(startColors.size)          addUpdateListener { animation -&gt;             if (System.currentTimeMillis() - deltaTime &gt; invalidateDelay) {                 val animatedFraction = animation.animatedValue as Float                 deltaTime = System.currentTimeMillis()                  \/\/ \u0421\u043c\u0435\u0448\u0438\u0432\u0430\u0435\u043c \u0446\u0432\u0435\u0442\u0430                 for (i in 0..mixedColors.lastIndex) {                     mixedColors[i] = ColorUtils.blendARGB(startColors[i], endColors[i], animatedFraction)                 }                  \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0442\u0435\u043d\u044c                 shapeDrawable.paint.shader = SweepGradient(                     centerX,                     centerY,                     mixedColors,                     null                 )                 shapeDrawable.invalidateSelf()             }         }         repeatMode = ValueAnimator.REVERSE         repeatCount = Animation.INFINITE         setDuration(duration)         start()     } }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c:<\/p>\n<pre><code class=\"kotlin\">\/\/ \u0412\u0442\u043e\u0440\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0446\u0432\u0435\u0442\u0430\u043c\u0438. \u0420\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439. val endColors = intArrayOf( \tColor.RED, \tColor.WHITE, \tColor.RED ) animateShadow( \tshapeDrawable = shadowDrawable,   startColors = colors,   endColors = endColors,   duration = 2000,   centerX = centerX,   centerY = centerY )<\/code><\/pre>\n<\/p>\n<p>\u0412\u0441\u0435. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043d\u043e\u043f\u043a\u043e\u0439, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c  ripple \u044d\u0444\u0444\u0435\u043a\u0442 \u0434\u043b\u044f foreground \u0432\u044c\u044e\u0445\u0438 \u0438 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043c \u043e\u0442\u0441\u0442\u0443\u043f, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0441 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0430\u0441\u044c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/530376\/\"> https:\/\/habr.com\/ru\/post\/530376\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-313957","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=313957"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313957\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}