在动画后显示元素

我希望在点击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);

慕的地6264312
浏览 98回答 1
1回答

梦里花落0921

您可以使用 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) {&nbsp; &nbsp; /* Add each frame to our animation drawable */&nbsp; &nbsp; for (int i = 0; i < aniDrawable.getNumberOfFrames(); i++) {&nbsp; &nbsp; &nbsp; &nbsp; this.addFrame(aniDrawable.getFrame(i), aniDrawable.getDuration(i));&nbsp; &nbsp; }}@Overridepublic void start() {&nbsp; &nbsp; super.start();&nbsp; &nbsp; /*&nbsp; &nbsp; &nbsp;* Call super.start() to call the base class start animation method.&nbsp; &nbsp; &nbsp;* Then add a handler to call onAnimationFinish() when the total&nbsp; &nbsp; &nbsp;* duration for the animation has passed&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; mAnimationHandler = new Handler();&nbsp; &nbsp; mAnimationHandler.post(new Runnable() {&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void run() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onAnimationStart();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp; mAnimationHandler.postDelayed(new Runnable() {&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void run() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onAnimationFinish();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }, getTotalDuration());}/**&nbsp;* Gets the total duration of all frames.&nbsp;*&nbsp;* @return The total duration.&nbsp;*/public int getTotalDuration() {&nbsp; &nbsp; int iDuration = 0;&nbsp; &nbsp; for (int i = 0; i < this.getNumberOfFrames(); i++) {&nbsp; &nbsp; &nbsp; &nbsp; iDuration += this.getDuration(i);&nbsp; &nbsp; }&nbsp; &nbsp; return iDuration;}/**&nbsp;* Called when the animation finishes.&nbsp;*/public abstract void onAnimationFinish();/**&nbsp;* Called when the animation starts.&nbsp;*/public abstract void onAnimationStart();}现在像这段代码一样使用它。TextView tv = (TextView) findViewById(R.id.iv_testing_testani);tv.setOnClickListener(new OnClickListener() {&nbsp; &nbsp; public void onClick(final View v) {&nbsp; &nbsp; &nbsp; &nbsp; // Pass our animation drawable to our custom drawable class&nbsp; &nbsp; &nbsp; &nbsp; CustomAnimationDrawableNew cad = new CustomAnimationDrawableNew(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (AnimationDrawable) getResources().getDrawable(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.drawable.anim_test)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void onAnimationStart() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Animation has started...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void onAnimationFinish() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Animation has finished...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; // Set the views drawable to our custom drawable&nbsp; &nbsp; &nbsp; &nbsp; v.setBackgroundDrawable(cad);&nbsp; &nbsp; &nbsp; &nbsp; // Start the animation&nbsp; &nbsp; &nbsp; &nbsp; cad.start();&nbsp; &nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java