亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在動畫后顯示元素

在動畫后顯示元素

慕的地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 關注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號