我可以在Backstack上放一个尚未初始化的片段吗?

时间:2015-05-23 19:36:18

标签: android android-fragments back-stack

我想从backstack中删除一个片段,并将另一个片段放在尚未创建的位置。下面是我想要实现的目标。

enter image description here

有没有办法实现这个目标?

修改

正如@Elltz指出的那样,这是不可能的。所以我的问题就变成了

  1. 是否可以从后堆栈中销毁最后一个片段?

  2. 我是否可以手动按下后退按钮以提供与后堆栈不同的片段?

2 个答案:

答案 0 :(得分:2)

  

想要从backstack中删除一个片段并放入另一个片段

您无法手动重新排列@background: #1d1f21; @foreground: #ddd; @hotpink: #CC0066; @pinkpurple: #CC00FF; @neongreen: #99FF00; /* Code Styling */ .CodeMirror, .CodeMirror-scroll { background-color: @background; color: @foreground; } .CodeMirror-focused .CodeMirror-activeline-background { background: #2f2f2f; } .show-line-padding .CodeMirror-focused .CodeMirror-activeline-background { box-shadow: inset 15px 0 0 0 #000; } .CodeMirror-focused .CodeMirror-activeline { .CodeMirror-gutter-elt { background: rgba(0, 0, 0, 0.2); color: #fff; } .inline-widget .CodeMirror-gutter-elt { color: #767676; } } .cm-atom, .cm-string, .cm-string-2, .cm-hr {color: @hotpink;} .cm-number, .cm-attribute, .cm-plus {color: @pinkpurple;} .cm-def, .cm-property {color: @neongreen;} .cm-variable, .cm-variable-2, .cm-variable-3, .cm-operator, .cm-meta, .cm-bracket {color: @foreground;} .cm-comment {color: #767676;} .cm-error, .cm-minus {color: #dc322f;} .cm-header {color: #d85896;} .cm-link {color: @pinkpurple; text-decoration: none;} .cm-rangeinfo {color: #656de8;} .cm-keyword, .cm-qualifier, .cm-builtin, .cm-tag, .cm-quote {color: #656de8;} /* Extra CSS */ .CodeMirror-searching { background-color: #660066; &.searching-current-match { background-color: #6600CC; } } .CodeMirror-cursor { border-left: 1px solid #c5c8c6 !important; } .CodeMirror-gutters { background-color: @background; border-right: none; } .CodeMirror-linenumber { color: #767676; } .CodeMirror .CodeMirror-selected { background: #333f48; } .CodeMirror-focused .CodeMirror-selected { background: #0099FF; } .CodeMirror-matchingbracket, .CodeMirror-matchingtag { /* Ensure visibility against gray inline editor background */ background-color: #2e5c00; color: @foreground !important; } .CodeMirror-overwrite .CodeMirror-cursor { border-left: none !important; border-bottom: 1px solid #fff; } /* CodeMirror's use of descendant selectors for certain styling causes problems when editors are nested because, for items in the inner editor, the left-hand clause in the selector will now match either the actual containing CodeMirror instance *OR* the outer "host" CodeMirror instance. TODO (issue #324): We'll still have problems if editors can be nested more than one level deep, or if any other descendant-selector-driven CM styles can differ between inner & outer editors (potential problem areas include line wrap and coloring theme: basically, anything in codemirror.css that uses a descandant selector where the CSS class name to the left of the space is something other than a vanilla .CodeMirror) */ .CodeMirror { .CodeMirror { background: transparent; } .CodeMirror .CodeMirror-gutters { background: transparent; border-right: none; } .CodeMirror .CodeMirror-activeline-background { background: transparent; } .CodeMirror .CodeMirror-activeline .CodeMirror-gutter-elt { background: transparent; color: #767676; } .CodeMirror-focused .CodeMirror-activeline-background { background: #2f2f2f; } .CodeMirror-focused .CodeMirror-activeline { .CodeMirror-gutter-elt { background: rgba(0, 0, 0, 0.2); color: #fff; } } } .CodeMirror-foldgutter-open:after { color: #666; } .CodeMirror-foldgutter-folded:after { color: #aaa; } .CodeMirror.over-gutter, .CodeMirror-activeline { .CodeMirror-foldgutter-open:after { color: #888; } } .CodeMirror-foldmarker { border-color: #000; color: #ccc; background-color: #444; } /* Non-editor styling */ .image-view, .not-editor { background-color: @background; } .view-pane .image-view { color: @foreground; } 。你只能听,观察和称呼它。查看BackstackEntry因此第一个没有

  

并将另一个片段放在尚未创建的位置

你的意思是PopBackstack(String name, int flags) null?..你也不能分配对Fragment对象的引用,第二个没有

  

有没有办法实现这个目标?

确认编号

修改

!的

  

是否可以从后堆栈中销毁最后一个片段?

你可以;使用FragmentManager& FragmentTransaction

null

第一个是

  

我是否可以手动按下后退按钮以提供与后堆栈不同的片段?

是的,您可以,但是您必须在FragmentManager fm = FragmentActivity.getSupportFragmentManager(); fm.beginTransaction().remove( fm.getBackStackEntryAt(fm.getBackStackEntryCount()-1);); FragmentActivity中执行此操作,因此您需要一些Activity或您自己的逻辑,或者 使用你自己的逻辑实现interface,这实际上就是我用逻辑讨论的BackStackChangedListener,这个监听器会在interface进入或离开Fragment时得到通知,因此< em>第二个是

第三个是徒劳。

希望对Sir先生有所帮助。

答案 1 :(得分:0)

你实际上不能这样做,但你可以做的是,制作这些tansition但隐藏

  • 从片段2转到片段3

  • 从3开始到片段4。

隐藏我的意思是,该用户看不到这种情况(您可以将布局可见性设置为已消失)。

但是这样,片段2将在堆栈中。

要从堆栈中取出片段2,请执行以下隐藏操作:

  • 返回1

  • 从1

  • 转到3
  • 从3开始4。

希望这有帮助。