代码之家  ›  专栏  ›  技术社区  ›  Prasoon Shrivastav

在android游戏的Result活动中显示的Star图像上的动画效果

  •  2
  • Prasoon Shrivastav  · 技术社区  · 13 年前

    我正在android中开发一个游戏,在每个级别完成后,都会显示一个Result活动,显示用户的分数,并根据分数给出星星。现在,在“结果”活动中有 3个图像视图 属于 灰色恒星 以及那些我想与之一起展示的东西 动画金星 但在播放动画时,灰色的星星会被隐藏起来,只有金色的星星似乎在移动,并被放置在隐藏的灰色星星上。 我想知道我该怎么做 最左边的灰色恒星仍然可见 直到a 金星来了,坐在上面

    问题:金星出现并坐落在看不见的灰色恒星上,但在金星出现并完全落在它上面之前,灰色恒星应该是可见的

    enter image description here

    问题:在动画开始时,最左边的星星将不可见。

    enter image description here

    Java代码:

    Myanim1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha_scale_left);
    starIv1=(ImageView)findViewById(R.id.starGrey1ImageView);
    
    starIv1.clearAnimation();
    starIv1.setImageResource(R.drawable.star);
    starIv1.startAnimation(Myanim1);
    

    动画xml

    <translate
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:fromXDelta="-300%"
     android:toXDelta="0%"
     android:fromYDelta="-700%"
     android:toYDelta="0%"
     android:duration="1200"  
     android:zAdjustment="bottom"
     android:interpolator="@android:anim/bounce_interpolator">
    </translate>
    
    <rotate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1200"
        android:interpolator="@android:anim/linear_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
    
        android:fromDegrees="0"
        android:toDegrees="360">
        </rotate>
    

    1 回复  |  直到 13 年前
        1
  •  0
  •   goodm    13 年前

    我认为你不能,你必须在当前的ImageView上添加新的ImageView并使其动画化。你可以保留3颗灰色的星星作为一个ImageView,并为金星添加3个将被隐藏并动画化的ImageView。

    如果你想避免它,只需制作双重动画。就像灰色的开始消失 在黄金出现之后

    类似这样的内容: anim1-灰色消失 amim2-金色入口

    starIv1=(ImageView)findViewById(R.id.starGrey1ImageView);
    
    starIv1.clearAnimation();
    anim1.setAnimationListener(new Animation.AnimationListener() {
    
            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onAnimationEnd(Animation animation) {
                starIv1.setImageResource(R.drawable.star);
                                starIv1.startAnimation(anim2);
            }
        })
    starIv1.startAnimation(anim1);