Parallax
public
abstract
class
Parallax
extends Object
Known indirect subclasses
| DetailsParallax |
Subclass of Parallax object that tracks overview row's top and bottom edge in DetailsFragment
or DetailsSupportFragment.
|
|
Parallax tracks a list of dynamic Propertys typically representing foreground UI
element positions on screen. Parallax keeps a list of ParallaxEffect objects which define
rules to mapping property values to ParallaxTarget.
Example:
// when Property "var1" changes from 15 to max value, perform parallax effect to
// change myView's translationY from 0 to 100.
Parallax parallax = new Parallax() {...};
p1 = parallax.addProperty("var1");
parallax.addEffect(p1.at(15), p1.atMax())
.target(myView, PropertyValuesHolder.ofFloat("translationY", 0, 100));
To create a ParallaxEffect, user calls addEffect(PropertyMarkerValue[]) with a
list of Parallax.PropertyMarkerValue which defines the range of Parallax.IntProperty or
Parallax.FloatProperty. Then user adds ParallaxTarget into
ParallaxEffect.
App may subclass Parallax.IntProperty or Parallax.FloatProperty to supply
additional information about how to retrieve Property value. RecyclerViewParallax is
a great example of Parallax implementation tracking child view positions on screen.
Restrictions of properties
- FloatProperty and IntProperty cannot be mixed in one Parallax
- Values must be in ascending order.
- If the UI element is unknown above screen, use UNKNOWN_BEFORE.
- if the UI element is unknown below screen, use UNKNOWN_AFTER.
- UNKNOWN_BEFORE and UNKNOWN_AFTER are not allowed to be next to each other.
These rules will be verified at runtime.
Subclass must override updateValues() to update property values and perform
ParallaxEffects. Subclass may call updateValues() automatically e.g.
RecyclerViewParallax calls updateValues() in RecyclerView scrolling. App might
call updateValues() manually when Parallax is unaware of the value change. For example,
when a slide transition is running, RecyclerViewParallax is unaware of translation value
changes; it's the app's responsibility to call updateValues() in every frame of
animation.
Summary
Nested classes |
class |
Parallax.FloatProperty
FloatProperty provide access to an index based integer type property inside
Parallax.
|
class |
Parallax.IntProperty
IntProperty provide access to an index based integer type property inside
Parallax.
|
class |
Parallax.PropertyMarkerValue<PropertyT>
Class holding a fixed value for a Property in Parallax.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public constructors
Parallax
public Parallax ()
Public methods
public ParallaxEffect addEffect (PropertyMarkerValue... ranges)
Create a ParallaxEffect object that will track source variable changes within a
provided set of ranges.
| Parameters |
ranges |
PropertyMarkerValue: A list of marker values that defines the ranges. |
addProperty
public final PropertyT addProperty (String name)
Add a new IntProperty in the Parallax object. App may override
createProperty(String, int).
| Parameters |
name |
String: Name of the property. |
| Returns |
PropertyT |
Newly created Property object. |
createProperty
public abstract PropertyT createProperty (String name,
int index)
Create a new Property object. App does not directly call this method. See
addProperty(String).
| Parameters |
name |
String |
index |
int: Index of the property in this Parallax object. |
| Returns |
PropertyT |
Newly created Property object.
|
getMaxValue
public abstract float getMaxValue ()
Return the max value which is typically size of parent visible area, e.g. RecyclerView's
height if we are tracking Y position of a child. The size can be used to calculate marker
value using the provided fraction of FloatPropertyMarkerValue.
| Returns |
float |
Size of parent visible area.
|
getProperties
public final List<PropertyT> getProperties ()
| Returns |
List<PropertyT> |
A unmodifiable list of properties.
|
removeAllEffects
public void removeAllEffects ()
Remove all ParallaxEffect objects.
updateValues
public void updateValues ()
Update property values and perform ParallaxEffects. Subclass may override and call
super.updateValues() after updated properties values.
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.