From dd2a3bc1ba1334495b76aaf008a696b2671c18fc Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Thu, 30 Apr 2015 15:11:43 -0700 Subject: [PATCH] Update alpha documentation bug:19412691 bug:20254728 Change-Id: I5bcdd888fb7b6498d43957a3ef32d3ad13683ad0 --- core/java/android/view/View.java | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index b5b7f0feede43..1be5b35cd3eed 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -10940,25 +10940,34 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - *

Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is - * completely transparent and 1 means the view is completely opaque.

+ * Sets the opacity of the view to a value from 0 to 1, where 0 means the view is + * completely transparent and 1 means the view is completely opaque. * - *

Note that setting alpha to a translucent value (0 < alpha < 1) can have significant - * performance implications, especially for large views. It is best to use the alpha property - * sparingly and transiently, as in the case of fading animations.

+ *

Note: setting alpha to a translucent value (0 < alpha < 1) + * can have significant performance implications, especially for large views. It is best to use + * the alpha property sparingly and transiently, as in the case of fading animations.

* *

For a view with a frequently changing alpha, such as during a fading animation, it is * strongly recommended for performance reasons to either override - * {@link #hasOverlappingRendering()} to return false if appropriate, or setting a - * {@link #setLayerType(int, android.graphics.Paint) layer type} on the view.

+ * {@link #hasOverlappingRendering()} to return false if appropriate, or setting a + * {@link #setLayerType(int, android.graphics.Paint) layer type} on the view for the duration + * of the animation. On versions {@link android.os.Build.VERSION_CODES#MNC} and below, + * the default path for rendering an unlayered View with alpha could add multiple milliseconds + * of rendering cost, even for simple or small views. Starting with + * {@link android.os.Build.VERSION_CODES#MNC}, {@link #LAYER_TYPE_HARDWARE} is automatically + * applied to the view at the rendering level.

* *

If this view overrides {@link #onSetAlpha(int)} to return true, then this view is * responsible for applying the opacity itself.

* - *

Note that if the view is backed by a - * {@link #setLayerType(int, android.graphics.Paint) layer} and is associated with a - * {@link #setLayerPaint(android.graphics.Paint) layer paint}, setting an alpha value less than - * 1.0 will supersede the alpha of the layer paint.

+ *

On versions {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} and below, note that if + * the view is backed by a {@link #setLayerType(int, android.graphics.Paint) layer} and is + * associated with a {@link #setLayerPaint(android.graphics.Paint) layer paint}, setting an + * alpha value less than 1.0 will supersede the alpha of the layer paint.

+ * + *

Starting with {@link android.os.Build.VERSION_CODES#MNC}, setting a translucent alpha + * value will clip a View to its bounds, unless the View returns false from + * {@link #hasOverlappingRendering}.

* * @param alpha The opacity of the view. *