public class

ReflectionLayout

extends FrameLayout
implements WrapperViewInterface
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ com.droidux.pack.layouts.widget.ReflectionLayout

Class Overview

ReflectionLayout is a layout container that will add a reflection to its child view. You can only place one child in it containing the entire contents to reflect; however, this child may itself be a layout manager with a complex hierarchy of objects, e.g. LinearLayout, RelativeLayout, etc.

If the child view is animated with an animation that has vertical translation, e.g. com.droidux.anim.FloorBounceAnimation, the reflection will be properly drawn simulating a reflection off a floor.

Important notes:

  • You must set the both the width and the height of the ReflectionLayout to WRAP_CONTENT, to create proper reflection effect.
  • Adding reflection requires memory resources. Don't overuse this widget to add reflection to very large views or too many views in one screen. For a simple bitmap reflection, use the ReflectionDrawable instead.

Note: ReflectionLayout uses a propriety mechanism to effectively and efficiently calculate and properly draw a reflection. This mechanism is currently not compatible with the Android's hardware acceleration feature introduced since API-11. Therefore, if you're using this widget in your activity, you have to disable the hardware acceleration, at least on the <activity/> level, by setting the hardwareAccelerated attribute to false.

For more information on Android's hardware acceleration features, please follow this links:

Summary

XML Attributes
Attribute Name Related Method Description
dux_effectStrength setEffectStrength(float) Specifies the strength of the effect to be apply to the view (see the dux_effectType attribute). 
dux_effectType setEffectType(int) Specifies the effect to be applied to the view. 
dux_floorGap setFloorGap(int) Specifies the distance from the bottom of the reflected view to the "floor". 
dux_reflected setReflected(boolean) Controls whether the view should be reflected. 
dux_reflectionHeight setReflectionHeightFactor(float) Specifies the factor to determine the reflection height. 
dux_reflectionStrength setReflectionStrength(float) Specifies the strength of the reflection. 
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
ReflectionLayout(Context context)
ReflectionLayout(Context context, AttributeSet attrs)
ReflectionLayout(Context context, AttributeSet attrs, int defStyle)
Public Methods
int getFloorGap()
Gets the distance between the bottom of the view to the 'floor' in a reflected view.
float getReflectionHeightFactor()
Gets the factor to calculate the reflection height.
float getReflectionStrength()
Gets the strength of the reflection in a reflected view.
int getReflectionTop()
Gets the top coordinate of the reflection bounds.
View getWrappedView()
Gets the wrapped view.
boolean isReflected()
Returns whether the view is reflected.
void setEffectStrength(float strength)
Sets the strength of the effect to be applied to the view returned by the adapter.
void setEffectType(int effect)
Sets the type of the effect to be applied to the view returned by the adapter.
void setFloorGap(int floorGap)
Sets the distance between the bottom of the view to the 'floor' in a reflected view.
void setReflected(boolean reflected)
Sets whether to draw a reflection of the child view.
void setReflectionHeightFactor(float factor)
Sets the factor to calculate the reflection height.
void setReflectionStrength(float strength)
Sets the strength of the reflection in a reflected view.
Protected Methods
FrameLayout.LayoutParams generateDefaultLayoutParams()
Returns a set of layout parameters with a width of MATCH_PARENT, and a height of MATCH_PARENT.
float getEffectStrength()
Gets the strength of the effect to be applied to the view returned by the adapter.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

[Expand]
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.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource
From interface com.droidux.pack.layouts.interfaces.WrapperViewInterface

XML Attributes

dux_effectStrength

Since: API Level

Specifies the strength of the effect to be apply to the view (see the dux_effectType attribute). Should be between 0.0 - 1.0 inclusive.

Related Methods

dux_effectType

Since: API Level

Specifies the effect to be applied to the view.

Must be one of the following constant values.

ConstantValueDescription
none0 Don't apply any effect.
dim1 Apply a dim effect. The dim effect will make the view appears darker.
fade2 Apply a fade effect. The fade effect will change the opacity/alpha of the view.

Related Methods

dux_floorGap

Since: API Level

Specifies the distance from the bottom of the reflected view to the "floor". Its value should be a dimension (such as "5dip").

Must be a dimension value, which is a floating point number appended with a unit such as "2.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

Related Methods

dux_reflected

Since: API Level

Controls whether the view should be reflected.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

Related Methods

dux_reflectionHeight

Since: API Level

Specifies the factor to determine the reflection height. The reflection height will be the specified factor multiplied by the view's getHeight(). Should be between 0.0 - 1.0 inclusive.

dux_reflectionStrength

Since: API Level

Specifies the strength of the reflection. This value is a factor that determines the opacity/alpha of the reflection. Should be between 0.0 - 1.0 inclusive.

Public Constructors

public ReflectionLayout (Context context)

Since: API Level 2.5

public ReflectionLayout (Context context, AttributeSet attrs)

Since: API Level 2.5

public ReflectionLayout (Context context, AttributeSet attrs, int defStyle)

Since: API Level 2.5

Public Methods

public int getFloorGap ()

Since: API Level 2.5

Gets the distance between the bottom of the view to the 'floor' in a reflected view.

Related XML Attributes
Returns
  • The floor gap.

public float getReflectionHeightFactor ()

Since: API Level 2.5

Gets the factor to calculate the reflection height. The reflection height is the factor multiply by the view's height.

Related XML Attributes
Returns
  • The reflection height factor.

public float getReflectionStrength ()

Since: API Level 2.5

Gets the strength of the reflection in a reflected view.

Related XML Attributes
Returns
  • The reflection strength

public int getReflectionTop ()

Since: API Level 2.5

Gets the top coordinate of the reflection bounds.

Returns
  • Top (y-axis) coordinate.

public View getWrappedView ()

Since: API Level 2.5

Gets the wrapped view.

Returns
  • The wrapped view.

public boolean isReflected ()

Since: API Level 2.5

Returns whether the view is reflected.

Related XML Attributes
Returns
  • true if reflected, false otherwise.

public void setEffectStrength (float strength)

Since: API Level 2.5

Sets the strength of the effect to be applied to the view returned by the adapter.

Related XML Attributes
Parameters
strength The effect strength; 0f-1f inclusive.

public void setEffectType (int effect)

Since: API Level 2.5

Sets the type of the effect to be applied to the view returned by the adapter.

Related XML Attributes
Parameters
effect The type of the effect.

public void setFloorGap (int floorGap)

Since: API Level 2.5

Sets the distance between the bottom of the view to the 'floor' in a reflected view.

Related XML Attributes
Parameters
floorGap The distance.

public void setReflected (boolean reflected)

Since: API Level 2.5

Sets whether to draw a reflection of the child view.

Related XML Attributes
Parameters
reflected If true, draw reflection at the bottom of the child view.

public void setReflectionHeightFactor (float factor)

Since: API Level 2.5

Sets the factor to calculate the reflection height. The reflection height is the factor multiply by the view's height.

Related XML Attributes
Parameters
factor The reflection height factor.

public void setReflectionStrength (float strength)

Since: API Level 2.5

Sets the strength of the reflection in a reflected view.

Related XML Attributes
Parameters
strength The reflection strength

Protected Methods

protected FrameLayout.LayoutParams generateDefaultLayoutParams ()

Since: API Level

Returns a set of layout parameters with a width of MATCH_PARENT, and a height of MATCH_PARENT.

Returns
  • a set of default layout parameters or null

protected float getEffectStrength ()

Since: API Level 2.5

Gets the strength of the effect to be applied to the view returned by the adapter.

Related XML Attributes
Returns
  • The effect strength

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Since: API Level

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.