Skip to content

Instantly share code, notes, and snippets.

@fnzainal
Last active July 20, 2017 04:19
Show Gist options
  • Save fnzainal/72eec5e566c2b42542cebd925119c2bb to your computer and use it in GitHub Desktop.
Save fnzainal/72eec5e566c2b42542cebd925119c2bb to your computer and use it in GitHub Desktop.
to create transition fragment
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import id.haisobat.android.R;
public class TransitionFragment extends Fragment {
public TransitionFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_transition, container, false);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setFragment(getActivity(), R.id.view_pager);
}
/**
* set fragment without animation
* @param context
* @param fragment
*/
public static void setFragment(FragmentActivity context, Fragment fragment){
FragmentTransaction transaction = context.getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container_fragment, fragment);
transaction.commit();
}
/**
* set the default frame layout with another fragment
* animation to NEXT fragment
* @param fragment : destination fragment
*/
public static void setNextFragment(FragmentActivity context, Fragment fragment){
FragmentTransaction transaction = context.getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
transaction.replace(R.id.container_fragment, fragment);
transaction.commit();
}
/**
* set the default frame layout with another fragment
* animation to back, prev fragment
* @param fragment : destination fragment
*/
public static void setPrevFragment(FragmentActivity context, Fragment fragment){
FragmentTransaction transaction = context.getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right);
transaction.replace(R.id.container_fragment, fragment);
transaction.commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment