...
package liu.basedemo.base; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import liu.basedemo.R; /** * Fragment基類 * Created by 劉楠 on 2016/7/28 0028.21:45 */ public abstract class BaseFragment extends Fragment { private Activity mActivity; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mActivity = getActivity(); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = bindLayout(inflater); return rootView; } /** * 子類必須實現 * * @param inflater * @return */ protected abstract View bindLayout(LayoutInflater inflater); @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initData(); initListener(); } /** * 子類可以不實現 */ private void initData() { } /** * 子類可以不實現 */ private void initListener() { } /** * 載入過場動畫 * * @param intent 意圖 */ @Override public void startActivity(Intent intent) { super.startActivity(intent); /** * 過場動畫 */ mActivity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); } /** * 載入過場動畫 * * @param intent 意圖 * @param requestCode 請求碼 */ @Override public void startActivityForResult(Intent intent, int requestCode) { super.startActivityForResult(intent, requestCode); mActivity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); } /** * 載入過場動畫 */ @Override public void onDestroy() { super.onDestroy(); mActivity.overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right); } }