2011-01-25 57 views
1

我正在開發電子書應用程序,需要從左到右和從右到左切換屏幕。我嘗試了很多我發現的樣本,但我沒有成功。當用戶從左到右和從右到左點擊屏幕時,如何頻繁更改屏幕。頁面轉換的基本思路是什麼?我通過開發者支持論壇線程"page-flip effect"尋找解決方案,但我看不到它。當用戶點擊位圖時執行屏幕切換

以下代碼不合邏輯。我在哪個位置必須實現翻轉屏幕中翻頁的效果以及如何實現?

public class TransitionScreen extends FullScreen implements Runnable{ 

    private int angle = 0; 
    Bitmap fromBmp,toBmp; 

    public TransitionScreen(){ 

    } 
    public TransitionScreen(AnimatableScreen from,AnimatableScreen to) { 

      fromBmp = new Bitmap(Display.getWidth(), Display.getHeight()); 
      toBmp = new Bitmap(Display.getWidth(), Display.getHeight()); 
     Graphics fromGraphics = Graphics.create(fromBmp); 
     Graphics toGraphics = Graphics.create(toBmp); 

     Object eventLock = getApplication().getEventLock(); 

     synchronized(eventLock) { 

       from.drawAnimationBitmap(fromGraphics); 

       to.drawAnimationBitmap(toGraphics); 
      // Interpolate myOffset to target 

      // Set animating = false if myOffset = target 

      invalidate(); 
     } 

     try { 
      synchronized (Application.getEventLock()) { 
       Ui.getUiEngine().suspendPainting(true); 
      } 

     } catch (final Exception ex) { 

     } 

    } 

    protected void paint(Graphics g){ 

      //control x,y positions of the bitmaps in the timer task and the paint will just paint where they go 

     g.drawBitmap(0,0, 360, 
       480, toBmp, 0, 0); 
     g.drawBitmap(0, 0, 360, 
       480, fromBmp, 0, 0);  
//  invalidate(); 

     } 

    protected boolean touchEvent(TouchEvent event) { 
     if (!this.isFocus()) 
      return true; 
     if (event.getEvent() == TouchEvent.CLICK) {  

    //  invalidate(); 
     } 
     return super.touchEvent(event); 
    } 

} 

回答

3

假設你正在使用5.0版本或以後的版本的操作系統,該頁面有一個簡單的例子:

http://docs.blackberry.com/en/developers/deliverables/11958/Screen_transitions_detailed_overview_806391_11.jsp

從哪兒弄來的代碼示例張貼在你的問題?該代碼看起來並不接近工作。

更新:您實際上可以非常簡單地爲此類動畫製作動畫。假設你知道如何使用Timer類,你基本上有一個類級別的變量來存儲你的第一個Bitmap的當前x位置(變量最初的值爲0)。在每個計時器刻度中,您從x位置減去一些量(但希望它移動每個刻度的許多像素),然後致電invalidate();

然後,在每次調用paint方法時,只需使用x位置變量爲調用的x參數繪製第一個位圖,然後使用x位置變量加上繪製第二個位圖的寬度第一個位圖。其結果是看到第一個位圖向左滑動,而第二個位圖從右側滑入。因爲這是java(這意味着計時器事件不是實時的 - 它們不能保證當你想要它們時發生),所以這個動畫將是不穩定和不平滑的。獲得這種流暢動畫的最佳方式是預渲染動畫單元格(其中每個動畫單元格都是兩個位圖之間轉換的漸進式組合),這樣在繪製方法中,渲染位圖。

+0

感謝您的回覆。我需要所有Touch版本的頁面翻頁效果,這是來自4.7 OS。如何處理頁面的翻頁效果。 – Koushik 2011-01-25 16:19:54