简体   繁体   English

Android补间动画:坐标如何在翻译中工作?

[英]android tween animation: how does coordinates works in translate?

I'm learning Tween Animation now, so I made a really simple animation looks like 我现在正在学习补间动画,所以我制作了一个非常简单的动画

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"
    android:duration="5000"
    android:fillAfter="true"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">

    <translate 
        android:fromXDelta="100%p"
        android:toXDelta="0%p"/>

</set>

I want the ImageView to move from right edge of the screen to the left. 我希望ImageView从屏幕的右边缘移到左侧。 The ImageView is in a fragment on the bottom of the screen, ImageView在屏幕底部的一个片段中,

public class BottomFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.bottom_fragment, container, false);

    ImageView back = (ImageView)view.findViewById(R.id.bottomback);
    Animation move = AnimationUtils.loadAnimation(getActivity(), R.anim.move);
    back.startAnimation(move);

    return view;
}
}

I thought fromXDelta="100%p" will put the left top corner of the image at the right edge, and toXDelta="0%p" will put the left top corner of the image at the left edge. 我以为fromXDelta="100%p"会将图像的左上角放在右边缘,而toXDelta="0%p"会将图像的左上角放在左边缘。 But the image seems to move from far away from the edge into the screen and stop at the middle of the screen. 但是图像似乎从远离边缘的位置移动到屏幕中,并停在屏幕中间。 And it seems like the position is the centre of the image instead of the left top corner. 位置似乎是图像的中心,而不是左上角。 I'm confused. 我糊涂了。 How does coordinate system in Tween Animation works? Tween Animation中的坐标系如何工作? How should I make it start at the edge of the screen/fragment? 我应该如何使其从屏幕/片段的边缘开始?

Well, now it seems like: 好吧,现在看起来像:

  1. The position of the picture is its centre, instead of left top corner. 图片的位置是图片的中心,而不是左上角。
  2. By using percentage, distance is relative to the width of the screen width. 通过使用百分比,距离是相对于屏幕宽度的宽度。 So, 0% means centre of the picture falls on the middle of the screen, 50% means the edge. 因此,0%表示图片的中心落在屏幕中间,50%表示边缘。 Thus, if I want the picture to move from one edge, I should make width of the picture the same as width of the screen, and then set fromXDelta=100% or 100%p . 因此,如果我希望图片从一个边缘移动,则应使图片的宽度与屏幕的宽度相同,然后将其设置为fromXDelta=100%100%p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM