Reputation: 77
I am trying to do a move + fade in animations to an imageView. I want it to slide from outside the screen to the middle of the screen. here's what I have tried :
activity xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/city"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:scaleType="fitEnd"
android:id="@+id/cityImage" />
</RelativeLayout>
move.xml
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromYDelta="-70%p"
android:toYDelta="0%p"
android:duration="1500" />
</set>
move function :
public void move(){
ImageView image = (ImageView)findViewById(R.id.cityImage);
Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
image.startAnimation(animation1);
}
as you can see I thought the javascript way by doing -70%p but it doesnt seem to work in android. can you please suggest me an other way?
Upvotes: 0
Views: 1347
Reputation: 678
Remove your move.xml
Then add in this
public void move(){
ImageView img_animation = (ImageView) findViewById(R.id.cityImage);
TranslateAnimation animation = new TranslateAnimation(600.0f, 0.0f, 0.0f, 0.0f);
animation.setDuration(5000);
img_animation.startAnimation(animation);
}
Move from Right to middle
Omg 600 is too much, just use 100 in fromXdelta
Upvotes: 3