Pergunta

I want to slide from left to right (opposite right to left in this code below). My current task is running correctly on button click.

Here is the source:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    Button btnopen = (Button)findViewById(R.id.btnWindowAnimation);
     
    btnopen.setOnClickListener(new View.OnClickListener() {
     
    @Override
    public void onClick(View v) {
     
    Intent i = new Intent(MainActivity.this, SecondActivity.class);
     
    Bundle bundle =ActivityOptions.makeCustomAnimation(getApplicationContext(), `              `R.anim.animation,R.anim.animation2).toBundle();
    startActivity(i, bundle);
     
    }
    });
    
}

Here Animation 1:

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

Here Animation 2:

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

Solução 2

Here is the first answer:

 <translate 
     android:fromXDelta="-100%" 
     android:toXDelta="0%"
     android:duration="500"/>
</set>

And here is the second XML:

<translate
 android:fromXDelta="0%"
  android:toXDelta="100%"
  android:duration="500" />
</set>

Outras dicas

This is for left to right animation:

<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
 <translate android:fromXDelta="-100%" android:toXDelta="0%"
         android:fromYDelta="0%" android:toYDelta="0%"
         android:duration="700"/>
</set>

This is for right to left animation:

<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
<translate
 android:fromXDelta="0%" android:toXDelta="100%"
 android:fromYDelta="0%" android:toYDelta="0%"
 android:duration="700" />
</set>

Check this link.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top