View.Alpha Property

Definition

The opacity of the view. -or- 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.

public virtual float Alpha { [Android.Runtime.Register("getAlpha", "()F", "GetGetAlphaHandler")] get; [Android.Runtime.Register("setAlpha", "(F)V", "GetSetAlpha_FHandler")] set; }
[<get: Android.Runtime.Register("getAlpha", "()F", "GetGetAlphaHandler")>]
[<set: Android.Runtime.Register("setAlpha", "(F)V", "GetSetAlpha_FHandler")>]
member this.Alpha : single with get, set

Property Value

The opacity of the view.

Attributes

Remarks

Property getter documentation:

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.

By default this is 1.0f.

Java documentation for android.view.View.getAlpha().

Property setter documentation:

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.

<p class="note"><strong>Note:</strong> 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.</p>

For a view with a frequently changing alpha, such as during a fading animation, it is strongly recommended for performance reasons to either override #hasOverlappingRendering() to return false if appropriate, or setting a #setLayerType(int, android.graphics.Paint) layer type on the view for the duration of the animation. On versions android.os.Build.VERSION_CODES#M 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 android.os.Build.VERSION_CODES#M, #LAYER_TYPE_HARDWARE is automatically applied to the view at the rendering level.

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

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

Starting with android.os.Build.VERSION_CODES#M, setting a translucent alpha value will clip a View to its bounds, unless the View returns false from #hasOverlappingRendering.

Java documentation for android.view.View.setAlpha(float).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also

  • HasOverlappingRendering
  • <xref:Android.Views.View.SetLayerType(Android.Views.LayerType%2c+Android.Graphics.Paint)>