如何在android中的动画中改变移动过渡中的对象方向?

时间:2016-11-28 06:25:43

标签: android android-layout animation transition

我想改变android动画中图像的方向。我的片段是

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;
    }
}
}

和我的动画XML是

<?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"
  />

它的输出是这样的:Output 但我想要这样的事情:expected outout

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

您也可以通过XML执行此操作:

 <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator" >
 <!-- Use startOffset to give delay between animations -->
<!-- Move -->
<translate
    android:duration="800"
    android:fillAfter="true"
    android:fromXDelta="0%p"
    android:startOffset="700"
    android:toXDelta="50%p" />
<translate
    android:duration="800"
    android:fillAfter="true"
    android:fromYDelta="0%p"
    android:startOffset="800"
    android:toYDelta="-10%p" />
 <translate
    android:duration="800"
    android:fillAfter="true"
    android:fromXDelta="0%p"
    android:startOffset="1300"
    android:toXDelta="75%p" />