當前位置: 首頁>>代碼示例>>Java>>正文


Java FragmentTransaction.addSharedElement方法代碼示例

本文整理匯總了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();

}
 
開發者ID:Vinetos,項目名稱:Hello-Music-droid,代碼行數:22,代碼來源:NavigationUtils.java

示例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();

}
 
開發者ID:Vinetos,項目名稱:Hello-Music-droid,代碼行數:22,代碼來源:NavigationUtils.java

示例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);
}
 
開發者ID:LonelyMushroom,項目名稱:aarLibrary,代碼行數:27,代碼來源:FragmentationDelegate.java

示例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();
}
 
開發者ID:Zeyad-37,項目名稱:RxRedux,代碼行數:23,代碼來源:BaseActivity.java

示例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();
}
 
開發者ID:harrylefit,項目名稱:eazycore,代碼行數:15,代碼來源:FragmentHelper.java

示例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();
}
 
開發者ID:harrylefit,項目名稱:eazycore,代碼行數:15,代碼來源:FragmentHelper.java

示例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();
}
 
開發者ID:Bynder,項目名稱:FragmentTransitionExample,代碼行數:35,代碼來源:MainActivity.java

示例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();
}
 
開發者ID:roshakorost,項目名稱:Phial,代碼行數:21,代碼來源:HomeActivity.java

示例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;
}
 
開發者ID:interactiveservices,項目名稱:utils-android,代碼行數:29,代碼來源:FragmentBuilder.java

示例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();
}
 
開發者ID:sciage,項目名稱:FinalProject,代碼行數:16,代碼來源:ActivityUtils.java

示例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);
		}
	}
}
 
開發者ID:aartikov,項目名稱:Alligator,代碼行數:13,代碼來源:LollipopTransitionAnimation.java

示例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();
}
 
開發者ID:Zeyad-37,項目名稱:RxRedux,代碼行數:16,代碼來源:UserDetailActivity.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:82,代碼來源:FragmentUtils.java

示例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;
}
 
開發者ID:hoangkien0705,項目名稱:Android-UtilCode,代碼行數:75,代碼來源:FragmentUtils.java

示例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;
}
 
開發者ID:pan2yong22,項目名稱:AndroidUtilCode-master,代碼行數:81,代碼來源:FragmentUtils.java


注:本文中的android.support.v4.app.FragmentTransaction.addSharedElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。