Android developmentAndroid tutorial

Android how to control screen translation Left to right

Screenshot 2019 08 14 10 09 27 841 com.rocareindia.omdeliveryboy
416views

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

Welcome to my blog! I’m Ritu Malik, and here at Codeplayon.com, we are dedicated to delivering timely and well-researched content. Our passion for knowledge shines through in the diverse range of topics we cover. Over the years, we have explored various niches such as business, finance, technology, marketing, lifestyle, website reviews and many others.