本文整理汇总了Java中android.support.v4.app.FragmentTransaction.addSharedElement方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.addSharedElement方法的具体用法?Java FragmentTransaction.addSharedElement怎么用?Java FragmentTransaction.addSharedElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.FragmentTransaction
的用法示例。
在下文中一共展示了FragmentTransaction.addSharedElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: navigateToAlbum
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@TargetApi(21)
public static void navigateToAlbum(Activity context, long albumID, Pair<View, String> transitionViews) {
FragmentTransaction transaction = ((AppCompatActivity) context).getSupportFragmentManager().beginTransaction();
Fragment fragment;
if (TimberUtils.isLollipop() && transitionViews != null && PreferencesUtility.getInstance(context).getAnimations()) {
Transition changeImage = TransitionInflater.from(context).inflateTransition(R.transition.image_transform);
transaction.addSharedElement(transitionViews.first, transitionViews.second);
fragment = AlbumDetailFragment.newInstance(albumID, true, transitionViews.second);
fragment.setSharedElementEnterTransition(changeImage);
} else {
transaction.setCustomAnimations(R.anim.activity_fade_in,
R.anim.activity_fade_out, R.anim.activity_fade_in, R.anim.activity_fade_out);
fragment = AlbumDetailFragment.newInstance(albumID, false, null);
}
transaction.hide(((AppCompatActivity) context).getSupportFragmentManager().findFragmentById(R.id.fragment_container));
transaction.add(R.id.fragment_container, fragment);
transaction.addToBackStack(null).commit();
}
示例2: navigateToArtist
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@TargetApi(21)
public static void navigateToArtist(Activity context, long artistID, Pair<View, String> transitionViews) {
FragmentTransaction transaction = ((AppCompatActivity) context).getSupportFragmentManager().beginTransaction();
Fragment fragment;
if (TimberUtils.isLollipop() && transitionViews != null && PreferencesUtility.getInstance(context).getAnimations()) {
Transition changeImage = TransitionInflater.from(context).inflateTransition(R.transition.image_transform);
transaction.addSharedElement(transitionViews.first, transitionViews.second);
fragment = ArtistDetailFragment.newInstance(artistID, true, transitionViews.second);
fragment.setSharedElementEnterTransition(changeImage);
} else {
transaction.setCustomAnimations(R.anim.activity_fade_in,
R.anim.activity_fade_out, R.anim.activity_fade_in, R.anim.activity_fade_out);
fragment = ArtistDetailFragment.newInstance(artistID, false, null);
}
transaction.hide(((AppCompatActivity) context).getSupportFragmentManager().findFragmentById(R.id.fragment_container));
transaction.add(R.id.fragment_container, fragment);
transaction.addToBackStack(null).commit();
}
示例3: start
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
void start(FragmentManager fragmentManager, SupportFragment from, SupportFragment to, String toFragmentTag, ArrayList<TransactionRecord.SharedElement> sharedElementList) {
FragmentTransaction ft = fragmentManager.beginTransaction();
Bundle bundle = to.getArguments();
if (sharedElementList == null) {
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
} else {
bundle.putBoolean(FRAGMENTATION_ARG_IS_SHARED_ELEMENT, true);
for (TransactionRecord.SharedElement item : sharedElementList) {
ft.addSharedElement(item.sharedElement, item.sharedName);
}
}
if (from == null) {
ft.add(bundle.getInt(FRAGMENTATION_ARG_CONTAINER), to, toFragmentTag);
bundle.putBoolean(FRAGMENTATION_ARG_IS_ROOT, true);
} else {
ft.add(from.getContainerId(), to, toFragmentTag);
if (from.getTag() != null) {
ft.hide(from);
}
}
ft.addToBackStack(toFragmentTag);
supportCommit(fragmentManager, ft);
}
示例4: addFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* Adds a {@link Fragment} to this activity's layout.
*
* @param containerViewId The container view to where add the fragment.
* @param fragment The fragment to be added.
*/
@SafeVarargs
public final void addFragment(int containerViewId, Fragment fragment, String currentFragTag,
Pair<View, String>... sharedElements) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
if (sharedElements != null) {
for (Pair<View, String> pair : sharedElements) {
fragmentTransaction.addSharedElement(pair.first, pair.second);
}
}
if (currentFragTag == null || currentFragTag.isEmpty()) {
fragmentTransaction.addToBackStack(fragment.getTag());
} else {
fragmentTransaction.addToBackStack(currentFragTag);
}
fragmentTransaction.add(containerViewId, fragment, fragment.getTag()).commit();
}
示例5: replaceFragmentWithSharedElement
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void replaceFragmentWithSharedElement(BaseFragment baseFragment, List<View> views) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction()
.replace(idContent, baseFragment);
if (views != null && !views.isEmpty()) {
for (View view : views) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
fragmentTransaction.addSharedElement(view, view.getTransitionName());
}
}
}
fragmentTransaction.addToBackStack(baseFragment.getClass().getName()).commitAllowingStateLoss();
}
示例6: addFragmentWithSharedElement
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void addFragmentWithSharedElement(BaseFragment baseFragment, List<View> views) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction()
.add(idContent, baseFragment);
if (views != null && !views.isEmpty()) {
for (View view : views) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
fragmentTransaction.addSharedElement(view, view.getTransitionName());
}
}
}
fragmentTransaction.addToBackStack(baseFragment.getClass().getName()).commitAllowingStateLoss();
}
示例7: performTransition
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void performTransition()
{
if (isDestroyed())
{
return;
}
Fragment previousFragment = mFragmentManager.findFragmentById(R.id.fragment_container);
Fragment nextFragment = Fragment2.newInstance();
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
// 1. Exit for Previous Fragment
Fade exitFade = new Fade();
exitFade.setDuration(FADE_DEFAULT_TIME);
previousFragment.setExitTransition(exitFade);
// 2. Shared Elements Transition
TransitionSet enterTransitionSet = new TransitionSet();
enterTransitionSet.addTransition(TransitionInflater.from(this).inflateTransition(android.R.transition.move));
enterTransitionSet.setDuration(MOVE_DEFAULT_TIME);
enterTransitionSet.setStartDelay(FADE_DEFAULT_TIME);
nextFragment.setSharedElementEnterTransition(enterTransitionSet);
// 3. Enter Transition for New Fragment
Fade enterFade = new Fade();
enterFade.setStartDelay(MOVE_DEFAULT_TIME + FADE_DEFAULT_TIME);
enterFade.setDuration(FADE_DEFAULT_TIME);
nextFragment.setEnterTransition(enterFade);
View logo = ButterKnife.findById(this, R.id.fragment1_logo);
fragmentTransaction.addSharedElement(logo, logo.getTransitionName());
fragmentTransaction.replace(R.id.fragment_container, nextFragment);
fragmentTransaction.commitAllowingStateLoss();
}
示例8: showFragmentById
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showFragmentById(int id) {
final Class<? extends Fragment> target = FRAGMENTS.get(id);
final Fragment fragment = Fragment.instantiate(this, target.getName());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setupFragmentTransition(fragment);
}
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, fragment);
for (Pair<View, String> sharedElement : sharedElements) {
transaction.addSharedElement(sharedElement.first, sharedElement.second);
}
sharedElements = new ArrayList<>();
transaction.commit();
}
示例9: createTransaction
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private FragmentTransaction createTransaction(@NonNull FragmentManager fragmentManager) {
if (parameters != null && !parameters.isEmpty()) {
fragment.setArguments(parameters);
}
FragmentTransaction transaction = fragmentManager.beginTransaction();
if (addToBackStack) {
transaction.addToBackStack(fragment.getClass().getSimpleName());
}
if (!sharedElement.isEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
for (View element : sharedElement) {
transaction.addSharedElement(element, element.getTransitionName());
}
}
if (animation != null) {
transaction.setCustomAnimations(animation.getEnter(),
animation.getExit(),
animation.getPopEnter(),
animation.getPopExit());
}
return transaction;
}
示例10: addFragmentToActivityWithSharedElement
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public static void addFragmentToActivityWithSharedElement(
@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId, String tag,
int enterAnimation, int exitAnimation, int popEnter, int popExit, View sharedElement,
String transitionName) {
checkNotNull(fragmentManager);
checkNotNull(fragment);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(enterAnimation, exitAnimation, popEnter, popExit);
fragmentTransaction.addSharedElement(sharedElement, transitionName);
fragmentTransaction.replace(frameId, fragment, tag);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commitAllowingStateLoss();
}
示例11: applyBeforeFragmentTransactionExecuted
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void applyBeforeFragmentTransactionExecuted(FragmentTransaction transaction, Fragment enteringFragment, Fragment exitingFragment) {
enteringFragment.setEnterTransition(mEnterTransition);
exitingFragment.setExitTransition(mExitTransition);
enteringFragment.setSharedElementEnterTransition(mSharedElementTransition);
enteringFragment.setAllowEnterTransitionOverlap(mAllowEnterTransitionOverlap);
if (mSharedElements != null) {
for (Pair<View, String> sharedElement : mSharedElements) {
transaction.addSharedElement(sharedElement.first, sharedElement.second);
}
}
}
示例12: addFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void addFragment(int containerViewId, Fragment fragment, String currentFragTag,
List<Pair<View, String>> sharedElements) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
if (sharedElements != null) {
for (Pair<View, String> pair : sharedElements) {
fragmentTransaction.addSharedElement(pair.first, pair.second);
}
}
if (currentFragTag == null || currentFragTag.isEmpty()) {
fragmentTransaction.addToBackStack(fragment.getTag());
} else {
fragmentTransaction.addToBackStack(currentFragTag);
}
fragmentTransaction.add(containerViewId, fragment, fragment.getTag()).commit();
}
示例13: operateFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* 操作fragment
*
* @param fragmentManager fragment管理器
* @param srcFragment 源fragment
* @param destFragment 目标fragment
* @param type 操作类型
* @param sharedElements 共享元素
* @return destFragment
*/
private static Fragment operateFragment(@NonNull final FragmentManager fragmentManager,
final Fragment srcFragment,
@NonNull Fragment destFragment,
final int type,
final SharedElement... sharedElements) {
if (srcFragment == destFragment) return null;
if (srcFragment != null && srcFragment.isRemoving()) {
Log.e("FragmentUtils", srcFragment.getClass().getName() + " is isRemoving");
return null;
}
String name = destFragment.getClass().getName();
Bundle args = destFragment.getArguments();
FragmentTransaction ft = fragmentManager.beginTransaction();
if (sharedElements == null || sharedElements.length == 0) {
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
} else {
for (SharedElement element : sharedElements) {// 添加共享元素动画
ft.addSharedElement(element.sharedElement, element.name);
}
}
switch (type) {
case TYPE_ADD_HIDE_FRAGMENT:
ft.hide(srcFragment);
case TYPE_ADD_FRAGMENT:
Fragment fragmentByTag = fragmentManager.findFragmentByTag(name);
if (fragmentByTag != null) {
if (fragmentByTag.isAdded()) {
ft.remove(fragmentByTag);
}
}
ft.add(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_HIDE)) ft.hide(destFragment);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_REMOVE_FRAGMENT:
ft.remove(destFragment);
break;
case TYPE_REMOVE_TO_FRAGMENT:
List<Fragment> fragments = getFragments(fragmentManager);
for (int i = fragments.size() - 1; i >= 0; --i) {
Fragment fragment = fragments.get(i);
if (fragment == destFragment) {
if (srcFragment != null) ft.remove(fragment);
break;
}
ft.remove(fragment);
}
break;
case TYPE_REPLACE_FRAGMENT:
ft.replace(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_ADD_POP_FRAGMENT:
popFragment(fragmentManager);
ft.add(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_HIDE_FRAGMENT:
ft.hide(destFragment);
break;
case TYPE_SHOW_FRAGMENT:
ft.show(destFragment);
break;
case TYPE_SHOW_HIDE_FRAGMENT:
ft.hide(srcFragment).show(destFragment);
break;
}
ft.commitAllowingStateLoss();
return destFragment;
}
示例14: operateFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* 操作fragment
*
* @param fragmentManager fragment管理器
* @param srcFragment 源fragment
* @param destFragment 目标fragment
* @param type 操作类型
* @param sharedElements 共享元素
* @return destFragment
*/
private static Fragment operateFragment(@NonNull FragmentManager fragmentManager,
Fragment srcFragment,
@NonNull Fragment destFragment,
int type,
SharedElement... sharedElements) {
if (srcFragment == destFragment) return null;
if (srcFragment != null && srcFragment.isRemoving()) {
LogUtils.e(srcFragment.getClass().getName() + " is isRemoving");
return null;
}
String name = destFragment.getClass().getName();
Bundle args = destFragment.getArguments();
FragmentTransaction ft = fragmentManager.beginTransaction();
if (sharedElements == null || sharedElements.length == 0) {
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
} else {
for (SharedElement element : sharedElements) {// 添加共享元素动画
ft.addSharedElement(element.sharedElement, element.name);
}
}
switch (type) {
case TYPE_ADD_FRAGMENT:
if (srcFragment != null) ft.hide(srcFragment);
ft.add(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_HIDE)) ft.hide(destFragment);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_REMOVE_FRAGMENT:
ft.remove(destFragment);
break;
case TYPE_REMOVE_TO_FRAGMENT:
List<Fragment> fragments = getFragments(fragmentManager);
for (int i = fragments.size() - 1; i >= 0; --i) {
Fragment fragment = fragments.get(i);
if (fragment == destFragment) {
if (srcFragment != null) ft.remove(fragment);
break;
}
ft.remove(fragment);
}
break;
case TYPE_REPLACE_FRAGMENT:
ft.replace(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_POP_ADD_FRAGMENT:
popFragment(fragmentManager);
ft.add(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_HIDE_FRAGMENT:
ft.hide(destFragment);
break;
case TYPE_SHOW_FRAGMENT:
ft.show(destFragment);
break;
case TYPE_HIDE_SHOW_FRAGMENT:
ft.hide(srcFragment).show(destFragment);
break;
}
ft.commitAllowingStateLoss();
return destFragment;
}
示例15: operateFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* 操作fragment
*
* @param fragmentManager fragment管理器
* @param srcFragment 源fragment
* @param destFragment 目标fragment
* @param type 操作类型
* @param sharedElements 共享元素
* @return destFragment
*/
private static Fragment operateFragment(@NonNull FragmentManager fragmentManager,
Fragment srcFragment,
@NonNull Fragment destFragment,
int type,
SharedElement... sharedElements) {
if (srcFragment == destFragment) return null;
if (srcFragment != null && srcFragment.isRemoving()) {
LogUtils.e(srcFragment.getClass().getName() + " is isRemoving");
return null;
}
String name = destFragment.getClass().getName();
Bundle args = destFragment.getArguments();
FragmentTransaction ft = fragmentManager.beginTransaction();
if (sharedElements == null || sharedElements.length == 0) {
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
} else {
for (SharedElement element : sharedElements) {// 添加共享元素动画
ft.addSharedElement(element.sharedElement, element.name);
}
}
switch (type) {
case TYPE_HIDE_ADD_FRAGMENT:
ft.hide(srcFragment);
case TYPE_ADD_FRAGMENT:
Fragment fragmentByTag = fragmentManager.findFragmentByTag(name);
if (fragmentByTag != null) {
destFragment = fragmentByTag;
} else {
ft.add(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_HIDE)) ft.hide(destFragment);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
}
break;
case TYPE_REMOVE_FRAGMENT:
ft.remove(destFragment);
break;
case TYPE_REMOVE_TO_FRAGMENT:
List<Fragment> fragments = getFragments(fragmentManager);
for (int i = fragments.size() - 1; i >= 0; --i) {
Fragment fragment = fragments.get(i);
if (fragment == destFragment) {
if (srcFragment != null) ft.remove(fragment);
break;
}
ft.remove(fragment);
}
break;
case TYPE_REPLACE_FRAGMENT:
ft.replace(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_POP_ADD_FRAGMENT:
popFragment(fragmentManager);
ft.add(args.getInt(ARGS_ID), destFragment, name);
if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name);
break;
case TYPE_HIDE_FRAGMENT:
ft.hide(destFragment);
break;
case TYPE_SHOW_FRAGMENT:
ft.show(destFragment);
break;
case TYPE_HIDE_SHOW_FRAGMENT:
ft.hide(srcFragment).show(destFragment);
break;
}
ft.commitAllowingStateLoss();
return destFragment;
}