Sheriff Said Elahl
Sheriff Said Elahl

Reputation: 177

slide transition using overridePendingTransition

I am trying to make slide between two activities but it is not effective. do I need a special style? I am working on "Theme.AppCompat.Light.NoActionBar"

I tried "Fade in/out" transition and it is working. but the slide is not .. what is the problem?

res/anim/enter:

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

res/anim/leave:

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

New Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.overridePendingTransition(R.anim.enter,
            R.anim.leave);
    setContentView(R.layout.activity_analyzer);
}

Main Activity:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 Mylist = (ListView) findViewById(R.id.navigation_list);
    drawerLayout = (DrawerLayout) findViewById(R.id.navigation);
    Mylist.setAdapter(new CustomListViewAdapter(getApplicationContext()));
    actionBarDrawerToggle = new ActionBarDrawerToggle(MainActivity.this,drawerLayout,toolbar,R.string.app_name,R.string.app_name);


Mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

if(newposition == 7) {
                drawerLayout.closeDrawers();
                Intent toAnalyzer = new Intent(MainActivity.this, Analyzer.class);
                startActivity(toAnalyzer);
                overridePendingTransition(R.anim.enter,
        R.anim.leave);

            }
}
});

Upvotes: 1

Views: 430

Answers (1)

xklakoux
xklakoux

Reputation: 707

You should put the line it in previous activity instead, like this:

    // after startActivity(intent);
    overridePendingTransition(R.anim.enter,
            R.anim.leave);

Upvotes: 1

Related Questions