Mhandroid Mhandroid - 9 days ago 6
Android Question

How to change direction of object in move transition in animation in android?

I want to change direction of an image in android animation.My fragment is

public class IconAnimation extends Fragment implements OnClickListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
final View v = inflater.inflate(R.layout.icon_animation, container,false);
return v;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.comedy:
Animation animation1 AnimationUtils.loadAnimation(getActivity(),
R.anim.slide);
ImageView image= (ImageView)v.findViewById(R.id.image);
image.startAnimation(animation1);
break;
}
}
}


and My animation XML is

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="150%p"
android:duration="800"
/>




Its output is something like this:Output
But I want something like this:expected outout

Answer
    final TranslateAnimation animationt1 = new TranslateAnimation(fromXoffset, toXOffset, fromYoffset,toYoffset);
    animationt1.setDuration(300);
    animationt1.setFillAfter(true);
    animationt1.setAnimationListener(this);
    yourView.startAnimation(animation1);