这应该很简单,对吧?所以-以下是我如何在XML中定义ViewSwitcher (为简洁起见省略了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。我是不是漏掉了什么明显的东西?
附言:我刚刚通过暴力手段发现这个方法是有效的:
switcher.setDisplayedChild(1);尽管如此-为什么bringToFront()不走运?
发布于 2010-09-22 03:20:12
bringToFront()实际上与ViewSwitcher没有任何关系,该方法继承自View类,代表对当前视图的z顺序操作:https://developer.android.com/reference/android/view/View.html#bringToFront()
您必须使用从ViewAnimator继承的showNext()和showPrevious()方法。
发布于 2013-03-26 16:36:26
在ViewSwitcher中,可以使用showPrevious()和showNext()方法在视图之间导航
或者使用也可以通过setDisplayedChild(int index)方法转到特定视图,其中索引可以是0或1
https://stackoverflow.com/questions/3763171
复制相似问题