Skip to content

Most visited

Recently visited

navigation

ShadowOverlayContainer

public class ShadowOverlayContainer
extends FrameLayout

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.support.v17.leanback.widget.ShadowOverlayContainer


Provides an SDK version-independent wrapper to support shadows, color overlays, and rounded corners. It's not always preferred to create a ShadowOverlayContainer, use ShadowOverlayHelper instead.

prepareParentForShadow(ViewGroup) must be called on parent of container before using shadow. Depending on sdk version, optical bounds might be applied to parent.

If shadows can appear outside the bounds of the parent view, setClipChildren(false) must be called on the grandparent view.

initialize(boolean, boolean, boolean) must be first called on the container. Then call wrap(View) to insert the wrapped view into the container.

Call setShadowFocusLevel(float) to control the strength of the shadow (focused shadows cast stronger shadows).

Call setOverlayColor(int) to control overlay color.

Summary

Inherited XML attributes

From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View

Constants

int SHADOW_DYNAMIC

Shadows depend on the size, shape, and position of the view.

int SHADOW_NONE

No shadow.

int SHADOW_STATIC

Shadows are fixed.

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

ShadowOverlayContainer(Context context)

Create ShadowOverlayContainer and auto select shadow type.

ShadowOverlayContainer(Context context, AttributeSet attrs)

Create ShadowOverlayContainer and auto select shadow type.

ShadowOverlayContainer(Context context, AttributeSet attrs, int defStyle)

Create ShadowOverlayContainer and auto select shadow type.

Public methods

void draw(Canvas canvas)

Manually render this view (and all of its children) to the given Canvas.

int getShadowType()

Returns the shadow type, one of SHADOW_NONE, SHADOW_STATIC, or SHADOW_DYNAMIC.

View getWrappedView()

Returns the wrapper view.

boolean hasOverlappingRendering()

Returns whether this View has content which overlaps.

void initialize(boolean hasShadow, boolean hasColorDimOverlay)

This method was deprecated in API level 22.0.0. use createShadowOverlayContainer(Context) instead.

void initialize(boolean hasShadow, boolean hasColorDimOverlay, boolean roundedCorners)

This method was deprecated in API level 23.1.0. use createShadowOverlayContainer(Context) instead.

static void prepareParentForShadow(ViewGroup parent)

prepareParentForShadow(ViewGroup) must be called on parent of container before using shadow.

void setOverlayColor(int overlayColor)

Set color (with alpha) of the overlay.

void setShadowFocusLevel(float level)

Set shadow focus level (0 to 1).

static boolean supportsDynamicShadow()

Returns true if the platform sdk supports dynamic shadows.

static boolean supportsShadow()

Return true if the platform sdk supports shadow.

void useDynamicShadow(float unfocusedZ, float focusedZ)

Sets the shadow type to SHADOW_DYNAMIC if supported and sets the elevation/Z values to the given parameters.

void useDynamicShadow()

Sets the shadow type to SHADOW_DYNAMIC if supported.

void useStaticShadow()

Sets the shadow type to SHADOW_STATIC if supported.

void wrap(View view)

Inserts view into the wrapper.

Protected methods

void onLayout(boolean changed, int l, int t, int r, int b)

Called from layout when this view should assign a size and position to each of its children.

Inherited methods

From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Constants

SHADOW_DYNAMIC

added in version 22.2.1
int SHADOW_DYNAMIC

Shadows depend on the size, shape, and position of the view.

Constant Value: 3 (0x00000003)

SHADOW_NONE

added in version 22.2.1
int SHADOW_NONE

No shadow.

Constant Value: 1 (0x00000001)

SHADOW_STATIC

added in version 22.2.1
int SHADOW_STATIC

Shadows are fixed.

Constant Value: 2 (0x00000002)

Public constructors

ShadowOverlayContainer

added in version 22.0.0
ShadowOverlayContainer (Context context)

Create ShadowOverlayContainer and auto select shadow type.

Parameters
context Context

ShadowOverlayContainer

added in version 22.0.0
ShadowOverlayContainer (Context context, 
                AttributeSet attrs)

Create ShadowOverlayContainer and auto select shadow type.

Parameters
context Context

attrs AttributeSet

ShadowOverlayContainer

added in version 22.0.0
ShadowOverlayContainer (Context context, 
                AttributeSet attrs, 
                int defStyle)

Create ShadowOverlayContainer and auto select shadow type.

Parameters
context Context

attrs AttributeSet

defStyle int

Public methods

draw

void draw (Canvas canvas)

Manually render this view (and all of its children) to the given Canvas. The view must have already done a full layout before this function is called. When implementing a view, implement onDraw(android.graphics.Canvas) instead of overriding this method. If you do need to override this method, call the superclass version.

Parameters
canvas Canvas: The Canvas to which the View is rendered.

getShadowType

added in version 22.2.1
int getShadowType ()

Returns the shadow type, one of SHADOW_NONE, SHADOW_STATIC, or SHADOW_DYNAMIC.

Returns
int

getWrappedView

added in version 22.2.1
View getWrappedView ()

Returns the wrapper view.

Returns
View

hasOverlappingRendering

boolean hasOverlappingRendering ()

Returns whether this View has content which overlaps.

This function, intended to be overridden by specific View types, is an optimization when alpha is set on a view. If rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer and then composited into place, which can be expensive. If the view has no overlapping rendering, the view can draw each primitive with the appropriate alpha value directly. An example of overlapping rendering is a TextView with a background image, such as a Button. An example of non-overlapping rendering is a TextView with no background, or an ImageView with only the foreground image. The default implementation returns true; subclasses should override if they have cases which can be optimized.

The current implementation of the saveLayer and saveLayerAlpha methods in Canvas necessitates that a View return true if it uses the methods internally without passing the CLIP_TO_LAYER_SAVE_FLAG.

Note: The return value of this method is ignored if forceHasOverlappingRendering(boolean) has been called on this view.

Returns
boolean true if the content in this view might overlap, false otherwise.

initialize

added in version 22.0.0
void initialize (boolean hasShadow, 
                boolean hasColorDimOverlay)

This method was deprecated in API level 22.0.0.
use createShadowOverlayContainer(Context) instead.

Initialize shadows, color overlay.

Parameters
hasShadow boolean

hasColorDimOverlay boolean

initialize

added in version 22.0.0
void initialize (boolean hasShadow, 
                boolean hasColorDimOverlay, 
                boolean roundedCorners)

This method was deprecated in API level 23.1.0.
use createShadowOverlayContainer(Context) instead.

Initialize shadows, color overlay, and rounded corners. All are optional. Shadow type are auto-selected based on useStaticShadow() and useDynamicShadow() call.

Parameters
hasShadow boolean

hasColorDimOverlay boolean

roundedCorners boolean

prepareParentForShadow

added in version 22.0.0
void prepareParentForShadow (ViewGroup parent)

prepareParentForShadow(ViewGroup) must be called on parent of container before using shadow. Depending on sdk version, optical bounds might be applied to parent.

Parameters
parent ViewGroup

setOverlayColor

added in version 22.0.0
void setOverlayColor (int overlayColor)

Set color (with alpha) of the overlay.

Parameters
overlayColor int

setShadowFocusLevel

added in version 22.0.0
void setShadowFocusLevel (float level)

Set shadow focus level (0 to 1). 0 for unfocused, 1f for fully focused.

Parameters
level float

supportsDynamicShadow

added in version 22.2.1
boolean supportsDynamicShadow ()

Returns true if the platform sdk supports dynamic shadows.

Returns
boolean

supportsShadow

added in version 22.0.0
boolean supportsShadow ()

Return true if the platform sdk supports shadow.

Returns
boolean

useDynamicShadow

added in version 22.2.1
void useDynamicShadow (float unfocusedZ, 
                float focusedZ)

Sets the shadow type to SHADOW_DYNAMIC if supported and sets the elevation/Z values to the given parameters.

Parameters
unfocusedZ float

focusedZ float

useDynamicShadow

added in version 22.2.1
void useDynamicShadow ()

Sets the shadow type to SHADOW_DYNAMIC if supported.

useStaticShadow

added in version 22.2.1
void useStaticShadow ()

Sets the shadow type to SHADOW_STATIC if supported.

wrap

added in version 22.0.0
void wrap (View view)

Inserts view into the wrapper.

Parameters
view View

Protected methods

onLayout

added in version 22.0.0
void onLayout (boolean changed, 
                int l, 
                int t, 
                int r, 
                int b)

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed boolean: This is a new size or position for this view

l int: Left position, relative to parent

t int: Top position, relative to parent

r int: Right position, relative to parent

b int: Bottom position, relative to parent

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)