2012-06-25 83 views
0

我的問題是,我想通過按Button從佈局1到任何其他佈局。 例如:可以使用ViewFlipper隨機更改佈局嗎?

從佈局1與setDisplayChild(R.id.layout3)從總共4個佈局轉到佈局3(不起作用)。

我做了一個container.xml中,包括四個版面,而是直接不使用flipper.showNext()flipper.showPrevious()兩次或這樣的事情,我不能去,例如從佈局2佈局4,方法showNext()showPrevious()只是前進或後退,我需要去任何其他佈局。

是否有方法讓ViewFlipper從佈局1(或其他佈局)轉到其他佈局(不是相鄰佈局)或ViewFlipper只知道下一個,前一個或第一個佈局(子)?

回答

1

是否有viewFlipper的方法從佈局1(或其他layots) 到其他佈局(不屬於neighoubrs佈局)或 知道腳蹼去只是去下一個,上一個或第一個佈局(子)?

是的,有從ViewAnimator類是ViewFlipper父,讓您移動ViewFlipper任何你想要孩子的方法setDisplayedChild

對於爲例:從與setDisplayChild(R.id.layout3)佈局1去 佈局3從總共4點的佈局。 (Doesen't工作)

setDisplayedChild需要你傳遞給它的是佈局的位置在ViewFlipper元素所需View不是ID像你使用它。所以,如果你要跳轉到的ViewFlipper一個孩子只需使用:

viewFlipper.setDisplayedChild(2); // jumps to the third child 
viewFlipper.setDisplayedChild(2); // another call like the one below will not move the ViewFlipper as it is already at the third child 
viewFlipper.setDisplayedChild(1); // jumps to the second child 

如果你想有隨機通過其子女ViewFlipper舉動,那麼你可以有:

Random mRandom = new Random(); 
viewFlipper.setDisplayedChild(mRandom.nextInt(4)); // 4 for 4 children 
+0

非常感謝你很多,我已經等待了一些我的迴應,但解決方案,我得到它是briliant!非常非常感謝你! –