Reputation: 3084
I am trying to make some kind of transition on Fragments, and i am using default application skeleton in eclipse for creating FragmentActivity. I noticed other posts for specifying custom transition animation from xml, but it is being done on Transaction, and none is using FragmentActivity. (Which is btw much easier.)
I would like to know how to make custom transitions in FragmentActivity. Thanks in advance!
EDIT: Somthing like this but for FragmentActivity.
MusicPlayerActivity.java
public class MusicPlayerActivity extends FragmentActivity {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// init pager and set its adapter
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
//other init code ...
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new MainFragment();
case 1:
return new AllSongsFragment();
case 2:
return new SettingsFragment();
default:
return null;
}
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
/**
* Get title for supplied Fragment number.
*/
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
case 2:
return getString(R.string.title_section3).toUpperCase(l);
}
return null;
}
}
//other methods
}
activity_music_player.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MusicPlayerActivity$OptionsFragment" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MusicPlayerActivity" >
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
<ListView
android:id="@+id/drawer"
android:layout_width="160dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#333333"
android:choiceMode="singleChoice" />
Upvotes: 0
Views: 324
Reputation: 7762
As you said in your comment, you're using a ViewPager
. This is slightly different to performing an animation on a FragmentTransaction
.
What you'll want to use is a ViewPager.PageTransformer
. There are some details on how to do that here
Upvotes: 1
Reputation: 1930
Question is not much clear to me. But i believe this may serve your purpose.
from: http://developer.android.com/reference/android/app/Activity.html#overridePendingTransition(int, int)
public void overridePendingTransition (int enterAnim, int exitAnim)
Added in API level 5 Call immediately after one of the flavors of startActivity(Intent) or finish() to specify an explicit transition animation to perform next.
As of JELLY_BEAN an alternative to using this with starting activities is to supply the desired animation information through a ActivityOptions bundle to {@link #startActivity(Intent, Bundle) or a related function. This allows you to specify a custom animation even when starting an activity from outside the context of the current top activity.
Parameters enterAnim A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation. exitAnim A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.
Upvotes: 0