gpt4 book ai didi

android - 使用 PageTransformer 时递归进入 executePendingTransactions

转载 作者:行者123 更新时间:2023-11-29 01:41:18 26 4
gpt4 key购买 nike

我直接使用教程 here. 中的 ZoomOutPageTransformer 我有一个抽屉导航,抽屉上的第一个项目是 ViewPager fragment 。这在第一次尝试时工作正常,但在我转到另一个 Activity 并返回后,它抛出了这个错误:

06-29 21:38:06.567    5905-5905/com.hidden.hidden E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.hidden.hidden, PID: 5905
java.lang.IllegalStateException: Recursive entry to executePendingTransactions
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1456)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:482)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager.setPageTransformer(ViewPager.java:623)
at com.hidden.hidden.MyFragment.onActivityCreated(MyFragment.java:56)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1512)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

我的代码

MyFragment.java 中的 onActivityCreated()

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

mPager = (ViewPager) getView().findViewById(R.id.pager);
mPager.setAdapter(new MyCustomAdapter(getFragmentManager()));

//Line 56
mPager.setPageTransformer(true, new ZoomOutPageTransformer());

mIndicator = (LinePageIndicator) getView().findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
}

ZoomOutPageTransformer.java

public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;

public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();

if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);

} else if (position <= 1) { // [-1,1]
// Modify the default slide transition to shrink the page as well
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
if (position < 0) {
view.setTranslationX(horzMargin - vertMargin / 2);
} else {
view.setTranslationX(-horzMargin + vertMargin / 2);
}

// Scale the page down (between MIN_SCALE and 1)
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);

// Fade the page relative to its size.
view.setAlpha(MIN_ALPHA +
(scaleFactor - MIN_SCALE) /
(1 - MIN_SCALE) * (1 - MIN_ALPHA));

} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}

同样,转换器直接来自 Android 开发者页面。

非常感谢您的帮助!

最佳答案

我在使用 PageTransformer 时遇到了同样的问题。就我而言,解决方案是在将适配器设置为我的 viewPager 之前调用 pager.setPageTransformer()。

cardsPager.setPageTransformer(true, new CardsPageTransformer());
cardsPager.setAdapter(new CardsPagerAdapter(getFragmentManager()));

关于android - 使用 PageTransformer 时递归进入 executePendingTransactions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24483077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com