MainActivity.java Source code

Java tutorial

Introduction

Here is the source code for MainActivity.java

Source

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.transition.ChangeBounds;
import android.transition.Scene;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.transition.TransitionManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

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

    public void goAnimate(View view) {

        ViewGroup root = (ViewGroup) findViewById(R.id.layout);
        Scene scene = new Scene(root);

        Transition transition = new ChangeBounds();
        TransitionManager.beginDelayedTransition(root, transition);

        TextView textViewTop = (TextView) findViewById(R.id.textViewTop);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textViewTop.getLayoutParams();
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 1);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
        textViewTop.setLayoutParams(params);

        TextView textViewBottom = (TextView) findViewById(R.id.textViewBottom);
        params = (RelativeLayout.LayoutParams) textViewBottom.getLayoutParams();
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 1);
        textViewBottom.setLayoutParams(params);

        TransitionManager.go(scene);

    }
}