Показать элемент после анимации - PullRequest
0 голосов
/ 10 июля 2019

Я хочу, чтобы после нажатия 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);
        falseRow36 = findViewById(R.id.falseRow36);
        trueRow36 = findViewById(R.id.trueRow36);
        trueRow43 = findViewById(R.id.trueRow43);
        falseRow44 = findViewById(R.id.falseRow44);
        falseRow45 = findViewById(R.id.falseRow45);
        falseRow43 = findViewById(R.id.falseRow43);
        trueRow44 = findViewById(R.id.trueRow44);
        trueRow45 = findViewById(R.id.trueRow45);
        trueRow46 = findViewById(R.id.trueRow46);
        falseRow46 = findViewById(R.id.falseRow46);
        trueRow53 = findViewById(R.id.trueRow53);
        trueRow54 = findViewById(R.id.trueRow54);
        trueRow55 = findViewById(R.id.trueRow55);
        trueRow56 =findViewById(R.id.trueRow56);
        falseRow53 = findViewById(R.id.falseRow53);
        falseRow54 = findViewById(R.id.falseRow54);
        falseRow55 = findViewById(R.id.falseRow55);
        falseRow56 =findViewById(R.id.falseRow56);

        animImage = findViewById(R.id.animImage);
        animImage.setBackgroundResource(R.drawable.question_mark);
        animationDrawable = (AnimationDrawable) animImage.getBackground();

        context = ExerciseWithExplain1.this;
        ad = new AlertDialog.Builder(context);
        ad.setTitle(R.string.explainLogic);
        ad.setMessage(R.string.logicForAnd);
        final int ir = 0;
        falseRow56.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                animImage.setVisibility(View.VISIBLE);
                    animationDrawable.start();
                    ad.show();
            }
        });
        trueRow56.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                animImage.setVisibility(View.VISIBLE);
                animationDrawable.start();
            }
        });
        falseRow55.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                animImage.setVisibility(View.VISIBLE);
                animationDrawable.start();
            }
        });

1 Ответ

0 голосов
/ 10 июля 2019

Вы можете попробовать это с помощью 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();
    }
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...