Android how to control screen translation Left to right

Hi, Developer in this Android tutorial you can learn how to control Android activity translation. like when  I am going screen A to Screen B so in these to screen you can see some white space and screen come from a background. So in these Articles, we learn how to control these screen translation screens come in and come out left to right and right to left.

So let’s start on the topic Android how to control screen translation Left to right.

Step 1: Create an Android project with an empty activity

After creating your project you can Add a folder In your res folder with the name anim and create layout file In your animation folder.

Create this XML file.

  •  left_slide.xml
  • right_slide.xml
  • right_slide_close.xml
  • right_slide_close_open.xml

left_slide.xml file Source code.

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="0"
    android:fromXDelta="100%"
    android:toXDelta="0%" >
</translate>

 right_slide.xml file Source code.

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="0"
    android:fromXDelta="0%"
    android:toXDelta="0%" >
</translate>

right_slide_close.xml file Source Code.

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="0"
    android:fromXDelta="-100%"
    android:toXDelta="0%" >
</translate>

right_slide_close_open.xml file Source Code.

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="0"
    android:fromXDelta="0%"
    android:toXDelta="0%" >
</translate>

Java Code for implementation in your activity Intent.

AddBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(Details_Screen.this,Partisipent.class);
        startActivity(intent);
        overridePendingTransition(R.anim.left_slide, R.anim.right_slide);
        finish();

    }
});

 

public void onBackPressed(){
    Intent intent = new Intent(Details_Screen.this,TabScreen.class);
    startActivity(intent);
    overridePendingTransition(R.anim.right_slide, R.anim.right_slide_close_open);
    finish();
}

Android Screen translation control and mange android activity UI

You may also like...