1

I've got an ImageView centered inside a RelativeLayout using android:layout_centerHorizontal="true" and android:layout_centerVertical="true".

Can I animate (move) it to let's say the bottom right corner, using XML and/or code? I'd like to specify the duration of the animation as well as possibly the curve.

Before:

<ImageView android:id="@+id/imageview01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@drawable/imagefile" />

After:

<ImageView
    android:id="@+id/imageview01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/imagefile" />
Jonny
  • 15,955
  • 18
  • 111
  • 232

2 Answers2

1

check Android Translate Animation

Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
  • Will/can this change android:layout_centerHorizontal="true" to "false" and android:layout_alignParentBottom to true (and similar)? – Jonny Nov 05 '12 at 13:04
  • As I don't know the target devices' dimensions I can't use absolute translations but need to keep using the relative commands as in the xml source. – Jonny Nov 06 '12 at 02:41
  • you can use percentage translation related to parent view. – Mohammad Ersan Nov 06 '12 at 07:34
  • but after you apply the animation you can keep the view in the last position it reached using `android:fillAfter="true"` in your xml. – Mohammad Ersan Nov 06 '12 at 07:38
1

Piggybacking on Mosh, this looks to be a helpful earlier answer:

Full example of how to programmatically do RotateAnimations?

Community
  • 1
  • 1
anthropomo
  • 4,100
  • 1
  • 24
  • 39