应该很容易吧?所以 - 这是我ViewSwitcher
在 XML 中定义的方式(为简洁起见,省略了 ID 和布局)
<ViewSwitcher android:layout_height="wrap_content" android:layout_width="fill_parent" >
<!-- First view, comes up OK -->
<LinearLayout android:id="@+id/header1">
<!-- some more controls: Progress bar, test view and the button -->
</LinearLayout>
<!-- second view. changing to the actual (not include) layout has no effect -->
<include android:id="@+id/header2" />
</ViewSwitcher>
然后在我的Java代码的某个地方我有这个代码
ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.profileSwitcher);
// more code that basically executes background search
// when call comes back - switch
switcher.bringToFront(); // does nothing
// switcher.bringChildToFront(findViewById(R.id.header2)); // no effect ether
只是没有切换。我为 API v. 3 (1.5+) 开发,令我惊讶的是,很少有对 ViewSwitcher 的引用。我在这里遗漏了一些明显的东西吗?
PS我刚刚通过蛮力发现这有效:
switcher.setDisplayedChild(1);
仍然 - 为什么没有运气bringToFront()
?