如何检测图像视图上的android动画是否完成(未结束)?

时间:2016-01-21 11:56:30

标签: android android-layout android-animation android-xml

我有2个环形状(小和大),我放在图像视图中。

small_ring.xml(大的形状只有不同颜色的3倍)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thickness="25dp"
android:useLevel="false">
<solid android:color="#D23232"/>
</shape>

两个图像视图都在activity_main.xml中,其中小视图位于大视图的中心。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
...>

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imvBig"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="@drawable/big_ring"
        android:visibility="invisible"/>

    <ImageView
        android:id="@+id/imvSmall"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/small_ring"/>
</RelativeLayout>
</RelativeLayout>

我有xml用于小型动画,它应该在2秒内增长到大型动画。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/linear_interpolator">
<scale
    android:duration="2000"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="3.0"
    android:toYScale="3.0"/>
</set>

当用户将手指放在图像视图上时,小的一个需要增长。如果用户在小形状填充大形状之前释放imageview,则不会发生任何事情。如果小形状填充大形状吐司出现。

@Override
public boolean onTouch(View v, MotionEvent event) {
    Animation scale = AnimationUtils.loadAnimation(this, R.anim.scale_up);

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        imgBig.setVisibility(View.VISIBLE);
        imgSmall.startAnimation(scale);
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        imgBig.setVisibility(View.INVISIBLE);
        imgSmall.clearAnimation();
    }


    scale.setAnimationListener(new Animation.AnimationListener() {
        long time;
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
                Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onAnimationRepeat(Animation animation) {
        }});
    return true;
}

我的问题是在两种情况下调用onAnimationEnd,当用户持有imageview和小形状填充大的形状时,如果用户在小形状填充大形状之前释放图像视图。有没有办法检测小形状是否已经长大到大尺寸?

0 个答案:

没有答案