Imageview Visible with onClick becoming invisible again?

Asked

Viewed 114 times

1

Talk to you guys, I have an Image that starts invisible and when clicking the button it becomes visible, but I need it to be invisible again because when clicking the button again, it has to appear again, due to having "disappeared" for time in the animation. Is there a simple way to do this? Because by methods or Classes, I always curl up. For I do not find the full explanation of how to pull the method and Talz.

Edit to Working Code.

btQuestions.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            seuLayout.setVisibility(View.VISIBLE);

            seuLayout.animate().alpha(0f).setDuration(5000);
            showButtons();


            }
        });

Note: youLayout has to be INVISIBLE in xml.

2 answers

1


You can use a Handler, which is a class that schedules tasks as per your need through a Thread according to the chosen time.

btQuestions.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        ImageView img = (ImageView) findViewById(R.id.image);

        img.setVisibility(View.VISIBLE);

        new Handler().postDelayed(new Runnable(){
            public void run() {
                img.setVisibility(View.INVISIBLE);
            }
        }, 3000);
    }
});
  • Marcel, thank you very much, I managed to do with some tutorials and gathering information from some 3 different places. kkkk. Then I came here was the answer.

0

Good morning. For if anyone ever needed it, it stayed that way. Note: the *seuLayout is the Relative, contrain, linear... that will do the action in everything inside. O . alpha(1f). setDuration(0); is to see your Ayout again because at the click of the button besides being visible had animation to disappear after a while. And to complete after a while youLayout turns back to INVISIBLE, so that the action of the button can make it VISIBLE again as needed.

private void showButtons(){

    Handler handler = new Handler();

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {

            seuLayout.setVisibility(View.INVISIBLE);
            seuLayout.animate().alpha(1f).setDuration(0);
    }
},2000); //Tempo para tornar seuLayout INVISIBLE.

}

To pull the method into onClick I used showButtons(); inside the button action.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.