我有 2 个片段,它们都有Scrollviews
,我从 aListView
中进行选择,并将第一个片段替换为具有滚动视图的另一个片段。
问题是,当我尝试用新的片段替换片段时,我收到一条错误消息,说明ScrollView can only contain one direct child
它是做什么的,它有一个RelativeLayout
包含所有内容的片段。
如果我将 ScrollView 从第一个片段视图中取出,我不会收到错误并且片段被替换得很好,但我需要第一个片段中的滚动视图。
是什么导致了这个问题,替换片段不会完全删除视图吗?
堆栈跟踪:
11-01 18:45:00.895: E/AndroidRuntime(3833): FATAL EXCEPTION: main
11-01 18:45:00.895: E/AndroidRuntime(3833): java.lang.IllegalStateException: ScrollView can host only one direct child
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.widget.ScrollView.addView(ScrollView.java:229)
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:840)
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.app.BackStackRecord.run(BackStackRecord.java:635)
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.os.Handler.handleCallback(Handler.java:615)
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.os.Handler.dispatchMessage(Handler.java:92)
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.os.Looper.loop(Looper.java:137)
11-01 18:45:00.895: E/AndroidRuntime(3833): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-01 18:45:00.895: E/AndroidRuntime(3833): at java.lang.reflect.Method.invokeNative(Native Method)
11-01 18:45:00.895: E/AndroidRuntime(3833): at java.lang.reflect.Method.invoke(Method.java:511)
11-01 18:45:00.895: E/AndroidRuntime(3833): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-01 18:45:00.895: E/AndroidRuntime(3833): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-01 18:45:00.895: E/AndroidRuntime(3833): at dalvik.system.NativeStart.main(Native Method)
这就是我替换片段的方式
ft.replace(R.id.frameTwo, individual);
ft.addToBackStack(null).commit();