为了账号安全,请及时绑定邮箱和手机立即绑定

在动画后显示元素

在动画后显示元素

慕的地6264312 2023-03-17 14:06:12
我希望在点击TextView显示动画之后(在动画之后)显示一些模态窗口。我该怎么做?Ps 我的动画包含在 XML 文件中<animation-list>public class ExerciseWithExplain1 extends AppCompatActivity {    private Button solution;    private TextView txtVWRed, explainForTable, solExplain, nextScreen, falseRow53, falseRow54, falseRow55, falseRow56, falseRow46, trueRow45, trueRow44, falseRow43, trueRow36, trueRow35, falseRow34, trueRow33, trueRow23, falseRow23, trueRow25, trueRow24, falseRow24, falseRow25, falseRow26, falseRow33, trueRow34, falseRow35, falseRow36, trueRow43, falseRow44, falseRow45, trueRow46, trueRow53, trueRow54, trueRow55, trueRow56, trueRow26;    LinearLayout layForTable;    AlertDialog.Builder ad;    Context context;    AnimationDrawable animationDrawable;    ImageView animImage;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_exercise_with_explain1);        trueRow23 = findViewById(R.id.trueRow23);        falseRow23 = findViewById(R.id.falseRow23);        falseRow24 = findViewById(R.id.falseRow24);        trueRow24 = findViewById(R.id.trueRow24);        trueRow25 = findViewById(R.id.trueRow25);        falseRow25 = findViewById(R.id.falseRow25);        trueRow26 = findViewById(R.id.trueRow26);        falseRow26 = findViewById(R.id.falseRow26);        falseRow33 = findViewById(R.id.falseRow33);        trueRow33 = findViewById(R.id.trueRow33);        trueRow34 = findViewById(R.id.trueRow34);        falseRow34 = findViewById(R.id.falseRow34);        falseRow35 = findViewById(R.id.falseRow35);        trueRow35 = findViewById(R.id.trueRow35);
查看完整描述

1 回答

?
梦里花落0921

TA贡献1772条经验 获得超6个赞

您可以使用 Custom AnimationDrwable 进行尝试


import android.graphics.drawable.AnimationDrawable;

import android.os.Handler;


public abstract class CustomAnimationDrawableNew extends AnimationDrawable {


/** Handles the animation callback. */

Handler mAnimationHandler;


public CustomAnimationDrawableNew(AnimationDrawable aniDrawable) {

    /* Add each frame to our animation drawable */

    for (int i = 0; i < aniDrawable.getNumberOfFrames(); i++) {

        this.addFrame(aniDrawable.getFrame(i), aniDrawable.getDuration(i));

    }

}


@Override

public void start() {

    super.start();

    /*

     * Call super.start() to call the base class start animation method.

     * Then add a handler to call onAnimationFinish() when the total

     * duration for the animation has passed

     */

    mAnimationHandler = new Handler();

    mAnimationHandler.post(new Runnable() {

        @Override

        public void run() {

            onAnimationStart();

        }

    });

    mAnimationHandler.postDelayed(new Runnable() {

        @Override

        public void run() {

            onAnimationFinish();

        }

    }, getTotalDuration());


}


/**

 * Gets the total duration of all frames.

 *

 * @return The total duration.

 */

public int getTotalDuration() {


    int iDuration = 0;


    for (int i = 0; i < this.getNumberOfFrames(); i++) {

        iDuration += this.getDuration(i);

    }


    return iDuration;

}


/**

 * Called when the animation finishes.

 */

public abstract void onAnimationFinish();

/**

 * Called when the animation starts.

 */

public abstract void onAnimationStart();

}


现在像这段代码一样使用它。


TextView tv = (TextView) findViewById(R.id.iv_testing_testani);


tv.setOnClickListener(new OnClickListener() {

    public void onClick(final View v) {


        // Pass our animation drawable to our custom drawable class

        CustomAnimationDrawableNew cad = new CustomAnimationDrawableNew(

                (AnimationDrawable) getResources().getDrawable(

                        R.drawable.anim_test)) {

            @Override

            void onAnimationStart() {

                // Animation has started...

            }


            @Override

            void onAnimationFinish() {

                // Animation has finished...

            }

        };


        // Set the views drawable to our custom drawable

        v.setBackgroundDrawable(cad);


        // Start the animation

        cad.start();

    }

});


查看完整回答
反对 回复 2023-03-17
  • 1 回答
  • 0 关注
  • 176 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号