MotionLabel

public class MotionLabel
extends View implements FloatLayout

java.lang.Object
   ↳ android.view.View
     ↳ androidx.constraintlayout.utils.widget.MotionLabel


This class is designed to created Complex Animated Single Line Text in MotionLayout

    color outlines
    Textured text
    PanX, PanY instead of Gravity

Summary

Inherited constants

Inherited fields

Public constructors

MotionLabel(Context context)
MotionLabel(Context context, AttributeSet attrs)
MotionLabel(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

float getRound()

Get the corner radius of curvature NaN = RoundPercent in effect.

float getRoundPercent()

Get the fractional corner radius of curvature.

float getTextBackgroundPanX()

Gets the pan from the center pan of 1 the image is "all the way to the right" if the images width is greater than the screen width, pan = 1 results in the left edge lining up if the images width is less than the screen width, pan = 1 results in the right edges lining up if image width == screen width it does nothing

float getTextBackgroundPanY()

gets the pan from the center pan of 1 the image is "all the way to the bottom" if the images width is greater than the screen height, pan = 1 results in the bottom edge lining up if the images width is less than the screen height, pan = 1 results in the top edges lining up if image height == screen height it does nothing

float getTextBackgroundRotate()

gets the rotation

float getTextBackgroundZoom()

gets the zoom where 1 scales the image just enough to fill the view

int getTextOutlineColor()
float getTextPanX()

Pan the Texture in the text in the x axis.

float getTextPanY()

Pan the Texture in the text in the y axis.

float getTextureHeight()

Pan the Texture in the text in the y axis.

float getTextureWidth()

get the width of the texture.

Typeface getTypeface()
void layout(float l, float t, float r, float b)

To convert to regular layout l = (int)(0.5f + lf); You are expected to do your own measure if you need it.

void layout(int l, int t, int r, int b)
void setGravity(int gravity)

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.

void setRound(float round)

Set the corner radius of curvature

void setRoundPercent(float round)

Set the corner radius of curvature as a fraction of the smaller side.

void setText(CharSequence text)
void setTextBackgroundPanX(float pan)

sets the pan from the center pan of 1 the image is "all the way to the right" if the images width is greater than the screen width, pan = 1 results in the left edge lining up if the images width is less than the screen width, pan = 1 results in the right edges lining up if image width == screen width it does nothing

void setTextBackgroundPanY(float pan)

sets the pan from the center pan of 1 the image is "all the way to the bottom" if the images width is greater than the screen height, pan = 1 results in the bottom edge lining up if the images width is less than the screen height, pan = 1 results in the top edges lining up if image height == screen height it does nothing

void setTextBackgroundRotate(float rotation)

sets the rotation angle of the image in degrees

void setTextBackgroundZoom(float zoom)

sets the zoom where 1 scales the image just enough to fill the view

void setTextFillColor(int color)

Set the color of the text.

void setTextOutlineColor(int color)

Sets the color of the text outline.

void setTextOutlineThickness(float width)
void setTextPanX(float textPanX)

Pan the Texture in the text in the x axis.

void setTextPanY(float textPanY)

Pan the Texture in the text in the y axis.

void setTextSize(float size)

set text size

void setTextureHeight(float mTextureHeight)

set the height of the texture.

void setTextureWidth(float mTextureWidth)

set the width of the texture.

void setTypeface(Typeface tf)

Protected methods

void onDraw(Canvas canvas)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited methods

Public constructors

MotionLabel

public MotionLabel (Context context)

Parameters
context Context

MotionLabel

public MotionLabel (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

MotionLabel

public MotionLabel (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

getRound

public float getRound ()

Get the corner radius of curvature NaN = RoundPercent in effect.

Returns
float Radius of curvature

getRoundPercent

public float getRoundPercent ()

Get the fractional corner radius of curvature.

Returns
float Fractional radius of curvature with respect to smallest size

getTextBackgroundPanX

public float getTextBackgroundPanX ()

Gets the pan from the center pan of 1 the image is "all the way to the right" if the images width is greater than the screen width, pan = 1 results in the left edge lining up if the images width is less than the screen width, pan = 1 results in the right edges lining up if image width == screen width it does nothing

Returns
float the pan in X. Where 0 is centered = Float. NaN if not set

getTextBackgroundPanY

public float getTextBackgroundPanY ()

gets the pan from the center pan of 1 the image is "all the way to the bottom" if the images width is greater than the screen height, pan = 1 results in the bottom edge lining up if the images width is less than the screen height, pan = 1 results in the top edges lining up if image height == screen height it does nothing

Returns
float pan in y. Where 0 is centered NaN if not set

getTextBackgroundRotate

public float getTextBackgroundRotate ()

gets the rotation

Returns
float the rotation in degrees

getTextBackgroundZoom

public float getTextBackgroundZoom ()

gets the zoom where 1 scales the image just enough to fill the view

Returns
float the zoom factor

getTextOutlineColor

public int getTextOutlineColor ()

Returns
int

getTextPanX

public float getTextPanX ()

Pan the Texture in the text in the x axis.

Returns
float pan of the Text -1 = left 0 = center +1 = right

getTextPanY

public float getTextPanY ()

Pan the Texture in the text in the y axis.

Returns
float the pan value 0 being centered in the center of screen.

getTextureHeight

public float getTextureHeight ()

Pan the Texture in the text in the y axis.

Returns
float pan of the Text -1 = top 0 = center +1 = bottom

getTextureWidth

public float getTextureWidth ()

get the width of the texture. Setting Float.NaN is the default Use the view size.

Returns
float the width of the texture

getTypeface

public Typeface getTypeface ()

Returns
Typeface the current typeface and style in which the text is being displayed.

layout

public void layout (float l, 
                float t, 
                float r, 
                float b)

To convert to regular layout l = (int)(0.5f + lf); You are expected to do your own measure if you need it. This will be called only during animation.

layout

public void layout (int l, 
                int t, 
                int r, 
                int b)

Parameters
l int

t int

r int

b int

setGravity

public void setGravity (int gravity)

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself. R.attr.gravity

Parameters
gravity int

See also:

setRound

public void setRound (float round)

Set the corner radius of curvature

Parameters
round float: the radius of curvature NaN = default meaning roundPercent in effect

setRoundPercent

public void setRoundPercent (float round)

Set the corner radius of curvature as a fraction of the smaller side. For squares 1 will result in a circle

Parameters
round float: the radius of curvature as a fraction of the smaller width

setText

public void setText (CharSequence text)

Parameters
text CharSequence

setTextBackgroundPanX

public void setTextBackgroundPanX (float pan)

sets the pan from the center pan of 1 the image is "all the way to the right" if the images width is greater than the screen width, pan = 1 results in the left edge lining up if the images width is less than the screen width, pan = 1 results in the right edges lining up if image width == screen width it does nothing

Parameters
pan float: sets the pan in X. Where 0 is centered

setTextBackgroundPanY

public void setTextBackgroundPanY (float pan)

sets the pan from the center pan of 1 the image is "all the way to the bottom" if the images width is greater than the screen height, pan = 1 results in the bottom edge lining up if the images width is less than the screen height, pan = 1 results in the top edges lining up if image height == screen height it does nothing

Parameters
pan float: sets the pan in X. Where 0 is centered

setTextBackgroundRotate

public void setTextBackgroundRotate (float rotation)

sets the rotation angle of the image in degrees

Parameters
rotation float: angle in degrees

setTextBackgroundZoom

public void setTextBackgroundZoom (float zoom)

sets the zoom where 1 scales the image just enough to fill the view

Parameters
zoom float: the zoom factor

setTextFillColor

public void setTextFillColor (int color)

Set the color of the text.

Parameters
color int: the color of the text

setTextOutlineColor

public void setTextOutlineColor (int color)

Sets the color of the text outline.

Parameters
color int: the color of the outline of the text

setTextOutlineThickness

public void setTextOutlineThickness (float width)

Parameters
width float

setTextPanX

public void setTextPanX (float textPanX)

Pan the Texture in the text in the x axis.

Parameters
textPanX float: pan of the Text -1 = left 0 = center +1 = right

setTextPanY

public void setTextPanY (float textPanY)

Pan the Texture in the text in the y axis.

Parameters
textPanY float: pan of the Text -1 = top 0 = center +1 = bottom

setTextSize

public void setTextSize (float size)

set text size

Parameters
size float: the size of the text

setTextureHeight

public void setTextureHeight (float mTextureHeight)

set the height of the texture. Setting Float.NaN is the default Use the view size.

Parameters
mTextureHeight float: the height of the texture

setTextureWidth

public void setTextureWidth (float mTextureWidth)

set the width of the texture. Setting Float.NaN is the default Use the view size

Parameters
mTextureWidth float: set the width of the texture Float.NaN clears setting

setTypeface

public void setTypeface (Typeface tf)

Parameters
tf Typeface

Protected methods

onDraw

protected void onDraw (Canvas canvas)

Parameters
canvas Canvas

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int