【问题标题】:How to change direction of object in move transition in animation in android?如何在android中的动画移动过渡中改变对象的方向?
【发布时间】:2016-11-28 06:25:43
【问题描述】:

我想在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

【问题讨论】:

    标签: android android-layout animation transition


    【解决方案1】:
        final TranslateAnimation animationt1 = new TranslateAnimation(fromXoffset, toXOffset, fromYoffset,toYoffset);
        animationt1.setDuration(300);
        animationt1.setFillAfter(true);
        animationt1.setAnimationListener(this);
        yourView.startAnimation(animation1);
    

    【讨论】:

    • 谢谢,但是我应该将什么值传递给 fromXoffset、toXoffset、fromYoffset、toYoffset?
    • 从应该 0,即你的观点的起点。 toXoffset 是水平方向。-x 是从右到左,+x 是从左到右。同样 fromYoffset 为 0,y 的起始视图。 toyoffset 是垂直方向。从上到下是-y,从下到tpo是+y
    • 这段代码对我有用
    • 你能看到一个勾号来否决我的答案吗?
    • 如果任何一个答案非常有帮助,您甚至可以投票赞成该答案,以便让最多的人受益,他们可以从中获得最大的利益。
    【解决方案2】:

    你也可以通过 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" />
    

    【讨论】:

      最近更新 更多