Transition between Navigation Panel and Fragment



My app which is consisted by a Navigation Drawer had some lags when I was opening a new activity by pressing any button from the Navigation Panel, so I added a Handler.It solved the lag but I don't like the way it acts: I slide the navigation panel -> I press on a button -> the panel slides back nice and slow and then the new activity comes like a flash, way too fast. Because of this I want to add a transition and here I'm stuck.



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

public void SelectItem(int position) {

Fragment fragment = null;
Bundle args = new Bundle();
switch (position) {

case 2:
fragment = new FragmentZero();
break;
case 3:
fragment = new FragmentOne();
break;
case 4:
fragment = new FragmentTwo();
break;
case 5:
fragment = new FragmentThree();
break;
case 7:
fragment = new FragmentTwo();
break;
case 8:
fragment = new FragmentZero();
break;
case 9:
fragment = new FragmentOne();
break;
case 10:
fragment = new FragmentTwo();
break;
case 11:
fragment = new FragmentZero();
break;
case 12:
fragment = new FragmentOne();
break;
case 14:
fragment = new FragmentZero();
break;
case 15:
fragment = new FragmentOne();
break;
case 16:
fragment = new FragmentTwo();
break;
default:
break;
}

FragmentManager fragmentManager = getFragmentManager();

FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setCustomAnimations(R.anim.left_to_right, R.anim.right_to_left, R.anim.left_to_right, R.anim.right_to_left);

transaction.replace(R.id.content_frame, fragment);
transaction.addToBackStack(null);
transaction.commit();
setTitle(dataList.get(position).getItemName());
}


right_to_left.xml



<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://ift.tt/nIICcg"
android:shareInterpolator="false"
android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="500" />


left_to_right.xml



<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://ift.tt/nIICcg"
android:shareInterpolator="false"
android:fromXDelta="-100%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="500"/>


The problem is that the transitions are not working...


fade_in.xml



<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://ift.tt/nIICcg"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="900"
/>
</set>


and fade_out.xml



<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://ift.tt/nIICcg"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="500"
/>
</set>


If I add the above ( fade_in and fade_out ) I get an error: Unknown Animator Name: Translate


why?!..


No comments:

Post a Comment