0

The problem is that, I am animating some views in my layout then trying to get the left and right variables of that views after the animation but the returning value is always the initial value when they were not animated.

I am using property animations like this:

For example this is moving the middle frame by 4/3 of its width and making it appear again on the screen by playing with its alpha...

middleFrame.animate().translationXBy(4*(middleFrame.getWidth())/3).alpha(1.0f);

However after the animation I should be able to get the changed left and right value of the middleFrame but when I try to do that as i said before it gives me the previous values..

I have checked this question and Romain Guy's answer How to get the absolute coordinates of a view

However, I couldn't quite understand when can I use the getLeft/Right or getLocationOnScreen() etc methods.

I have already tried getLocationOnScreen or getLocationInWindow but they return the same results.

Thanks in advance.

Community
  • 1
  • 1
Manny
  • 1
  • 2

1 Answers1

0

I also never understood why getLocationOnScreen and getLocationInWindow returns the same values...

getLeft/Right/Top/Bottom returns the offset to view parent in pixel. You can't use that for animations because this information is static and only provides information about the layout.

Simple example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <TextView  
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent" 
            android:text="@string/hello" />
        <TextView  
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent" 
            android:text="@string/hello" />
</LinearLayout>

If you use this layout and animate the first text view with a translation to the right side, it will overflow the second text view instead pushing it to the right side. So basically the first text view is still at its old position (getLeft/Right/Top/Bottom same value) but was internally moved to another position.

To come straight to the point: Animation is just a visual effect and has nothing to do with layout positioning.

Knickedi
  • 8,742
  • 3
  • 43
  • 45
  • I thought property animation also effects the real object properties thus the layout positioning too.? – Manny Sep 21 '11 at 09:40
  • Hmm. I thought of it that way. But someone might correct me please if im wrong. E.g. how would a rotation affect the layout?! – Knickedi Sep 21 '11 at 18:26