'Android - Relative_to_Parent Vs. Relative_To_Self

When dealing with TranslateAnimations, you can move a particular object from position A to position B. The co-ordinates for these positions can be denoted in Relative_To_Self vs. Relative_To_Parent? These positions are represented in percentages.

What exactly does this mean?

For examples, suppose I have a Relative_Layout whose width is set to Fill_Parent and an ImageView in it whose width is lets say 80pixels.

Here is the definition I am looking at:

public TranslateAnimation (int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

If I set my fromXType to Relative_to_parent and my from X value as 0.0. Does this mean that my imageView will start at the extreme left of the screen?

If I set it to Relative to Parent and fromXValue as -1.0.Does this mean that it will start from -80 pixels from where it is originally?

Are my assumptions correct? Thanks in advance for any help.



Solution 1:[1]

TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);

In that case;

Relative to parent (RELATIVE_TO_PARENT)

0.0f = ParentView.getLeft() value.
1.0f = ParentView.getRight() value.

Relative to self (RELATIVE_TO_SELF)

0.0f = SelfView.getLeft() value.
1.0f = SelfView.getRight() value.

For example

if parentView.getLeft() = 0, parentView.getRight() = 1000(px), self.getLeft() = 0, self.getRight = 100(px)

RELATIVE_TO_PARENT -> View will translate from 1000 to 0,

RELATIVE_TO_SELF -> View will translate from 100 to 0

Solution 2:[2]

Well, here's what the docs say for RELATIVE_TO_PARENT and RELATIVE_TO_SELF:

public static final int RELATIVE_TO_PARENT

The specified dimension holds a float and should be multiplied by the height or width of the parent of the object being animated.

public static final int RELATIVE_TO_SELF

The specified dimension holds a float and should be multiplied by the height or width of the object being animated.

Seems pretty clear to me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Karshin
Solution 2 kabuko