質問

簡単なはずですよね?だから - これが私が持っている方法です 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