Android 为什么我的动画没有在正确的点停止?

Android 为什么我的动画没有在正确的点停止?,android,animation,slide,ontouchlistener,Android,Animation,Slide,Ontouchlistener,在五月的应用程序中,我有两个动画。一个是从屏幕底部向顶部生长。它在我的startNewAnimation()方法中调用: 此方法在此方法中调用: ViewTreeObserver observer = ViewTimer.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override @SuppressWarnings("deprecation")

在五月的应用程序中,我有两个动画。一个是从屏幕底部向顶部生长。它在我的startNewAnimation()方法中调用:

此方法在此方法中调用:

ViewTreeObserver observer = ViewTimer.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
    @SuppressWarnings("deprecation")
public void onGlobalLayout() {
    Log.d(TAG, "onGlobalLayout");
        mViewHeight = ViewTimer.getHeight();
        startNewAnimation();
        ViewTimer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    }
});
我的另一个动画就像一个滑动按钮。它用于停止动画

@Override
public boolean onTouch(View view, MotionEvent event) {
AbsoluteLayout.LayoutParams layoutParams = (AbsoluteLayout.LayoutParams) view.getLayoutParams();

switch (event.getAction() & MotionEvent.ACTION_MASK) {

    case MotionEvent.ACTION_UP:
        showDialog();
        pauseAnimation();
        int endOfAnimation = findViewById(R.id.slide_included).getWidth() - mSlideView.getWidth();
        mSlideAnimation = new TranslateAnimation(event.getX(), endOfAnimation - layoutParams.x, 0, 0);
        mSlideAnimation.setDuration(1000);          
        mSlideAnimation.setFillAfter(true);
        mSlideView.startAnimation(mSlideAnimation);

        break;

    case MotionEvent.ACTION_MOVE:
        layoutParams.x = (int) event.getRawX();
        view.setLayoutParams(layoutParams);

        break;
    }
也就是说,当我移动幻灯片视图时,我调用pauseAnimation()方法来清除主动画

@Override
public boolean onTouch(View view, MotionEvent event) {
AbsoluteLayout.LayoutParams layoutParams = (AbsoluteLayout.LayoutParams) view.getLayoutParams();

switch (event.getAction() & MotionEvent.ACTION_MASK) {

    case MotionEvent.ACTION_UP:
        showDialog();
        pauseAnimation();
        int endOfAnimation = findViewById(R.id.slide_included).getWidth() - mSlideView.getWidth();
        mSlideAnimation = new TranslateAnimation(event.getX(), endOfAnimation - layoutParams.x, 0, 0);
        mSlideAnimation.setDuration(1000);          
        mSlideAnimation.setFillAfter(true);
        mSlideView.startAnimation(mSlideAnimation);

        break;

    case MotionEvent.ACTION_MOVE:
        layoutParams.x = (int) event.getRawX();
        view.setLayoutParams(layoutParams);

        break;
    }
问题是:当我的主动画停止时,如果它位于“幻灯片”按钮下方,则会一直绘制到幻灯片视图的顶部。我怎样才能解决这个问题

这是我的布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frame_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/time_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <View
            android:id="@+id/surface_view_timer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="0dp"
            android:background="#77B21B00" /> 
    </RelativeLayout>

<include
    android:id="@+id/slide_included"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|bottom"
    android:layout_margin="20dp"
    layout="@layout/slide" />

</FrameLayout>

slide.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/slide_layout"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_margin="20dp"
    android:background="#0000FF" >

    <View
        android:id="@+id/slide_to_pause"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#00FFFF" />
</AbsoluteLayout>