这应该很容易,对吗?所以 - 这就是我的样子 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

只是不切换。我为APIv。3(1.5+)开发,令我惊讶的是,对ViewSwitcher的参考很少。我在这里错过了明显的东西吗?

PS我刚刚通过蛮力发现这有效:

switcher.setDisplayedChild(1);

仍然 - 为什么不运气 bringToFront()?

有帮助吗?

解决方案

bringToFront() 实际上与 ViewSwitcher, ,该方法是从视图类继承的,代表当前视图的Z阶操作: https://developer.android.com/reference/android/view/view.html#bringtofront()

你必须使用 showNext()showPrevious() 继承的方法 ViewAnimator.

其他提示

ViewSwitcher 要在视图之间导航,您可以使用这些方法 showPrevious()showNext()

或使用也可以通过 setDisplayedChild(int index) 索引可以是索引的方法 0 或者 1

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top