2011-01-25 73 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