I have two activities and i want to make an animation in which when you click on a button in activity 1 it slide up out of the screen and opens activity 2 , and also in activity 2 there is a button when you click on it it slides up out of the screen and opens activity 1 .
so exiting an activity by going up out of the screen
and entering by going up into the screen .
which gives the feeling of scrolling .
So i started by making 2 activities and this anim folder that contains this tow animations sets:
slide_up_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0"
android:toYDelta="-100%p"
android:duration="@android:integer/config_longAnimTime"/>
</set>
slide_up_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%p"
android:toYDelta="0"
android:duration="@android:integer/config_longAnimTime"/>
</set>
And these are the two activities :
**
MainActivity.java**
package com.example.animationproject;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.transition.Slide;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, MainActivity2.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_up_in,R.anim.slide_up_out);
}
});
}
}
MainActivity2.java
package com.example.animationproject;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.transition.Fade;
import android.transition.Slide;
import android.view.View;
import android.widget.Button;
public class MainActivity2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Button button2 = findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity2.this, MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_up_in,R.anim.slide_up_out);
}
});
}
}
i tired it with API level 33 and 34 on the emulator it worked , but With My android14 Physcial device it does Something else .
Check the Videos here :
https://drive.google.com/drive/folders/1fF8OHnsE2fvZUDx9fuV_CErD1HgreBCf?usp=sharing