Android - Relative_to_Parent Vs. Relative_To_Self

When working with TranslateAnimations, you can move a specific object from position A to position B. Can the coordinates for these positions be designated Relative_To_Self or Relative_To_Parent? These positions are presented as a percentage.

What exactly does this mean?

As an example, suppose I have a Relative_Layout whose width is set to Fill_Parent and the ImageView in it whose width allows us to say that it is 80 pixels.

Here is the definition I'm 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 value from 0.0 is 0.0. Does this mean that my ImageView will start in the far left corner of the screen?

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

Are my assumptions correct? Thank you in advance for any help.

+4
source share
2 answers
 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 this case;

Regarding Parent ( RELATIVE_TO_PARENT )

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

Relatively self ( RELATIVE_TO_SELF )

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

for instance

 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

0
source

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

 public static final int RELATIVE_TO_PARENT 

The specified size contains a float and must be multiplied by the height or width of the parent of the animated object.

 public static final int RELATIVE_TO_SELF 

The specified size contains a float and must be multiplied by the height or width of the animated object.

It seems pretty clear to me.

-1
source

Source: https://habr.com/ru/post/1382108/


All Articles