Animation at the touch of a button

3

I have a registration screen where a default photo is already set. If I press on the photo it opens 2 options to change the photo. Or take the gallery or take a picture.

Clicking the button would like to add an effect. Please, can anyone give me a hint?

    
asked by anonymous 31.08.2016 / 19:01

1 answer

3

Below is a very basic and simple form of implementation. Remembering that to create an animation, it depends a lot on creativity. So if you want to do crazy things, you have to do a lot of research. In the code example below, a ImageView is created in which after the click will appear another two ImageButton in the sequence, which would be a btnFotoGaleria and another btnFotoCamera .

public class ActivityMain extends Activity{

    ImageView btnFotoPerfil;
    ImageButton btnFotoGaleria;
    ImageButton btnFotoCamera;

    // Animação
    Animation animFadein;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnFotoGaleria= (ImageButton) findViewById(R.id.btnFotoGaleria);
        btnFotoCamera= (ImageButton) findViewById(R.id.btnFotoCamera);

        // load the animation
        animFadein = AnimationUtils.loadAnimation(getApplicationContext(),
                R.anim.fade_in); 

        btnFotoPerfil= (ImageView) findViewById(R.id.btnFotoPerfil);
        // evento onclick no botao
        btnFotoPerfil.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                btnFotoGaleria.setVisibility(View.VISIBLE);
                btnFotoCamera.setVisibility(View.VISIBLE);

                // start the animation
                btnFotoGaleria.startAnimation(animFadein);
                btnFotoCamera.startAnimation(animFadein);
            }
        });       
    }
}

It's important to remember to set up the parameters of ImageButton by setting android:visibility="gone" so that they remain invisible until the user clicks.

Within res you need to create a directory named anim and a .xml for your animation, for example fade_in.xml with the following code below:

fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <alpha
        android:duration="1000"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="1.0" />

</set>

Details

31.08.2016 / 19:30