2011-04-13 35 views
0

我正试图设计一个启动画面及其上的活动指示器。 我成功创建了一个启动画面,但我的指示灯没有被添加到它, 它正在隐藏在图像下方,而我正在设置其布局。黑莓手机上的进度指示器闪屏

我该如何解决这个问题?

这里是我的代码:

package mypackage; 
import java.util.Timer; 
import java.util.TimerTask; 

import net.rim.device.api.system.Application; 
import net.rim.device.api.system.Bitmap; 
import net.rim.device.api.system.Display; 
import net.rim.device.api.ui.Field; 
import net.rim.device.api.ui.Graphics; 
import net.rim.device.api.ui.UiApplication; 
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorController; 
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorModel; 
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorView; 
import net.rim.device.api.ui.container.HorizontalFieldManager; 
import net.rim.device.api.ui.container.VerticalFieldManager; 

import net.rim.device.api.ui.container.MainScreen; 
//import net.rim.device.api.ui.extension.container.EyelidFieldManager; 


public final class SplashScreen extends SplashScreenPage 
{ 


    public SplashScreen() 
    {   
    super(Bitmap.getBitmapResource("splash-blackberry.png"),2); 
    } 
} 
class SplashScreenPage extends MainScreen 

{ 

    VerticalFieldManager vfm= new VerticalFieldManager(Field.FIELD_VCENTER); 


HorizontalFieldManager hfm = new HorizontalFieldManager(Field.FIELD_VCENTER) 
    { 
     protected void sublayout(int maxWidth, int maxHeight) 
    { 
     super.sublayout(360,60); 
     setExtent(360, 60); 

     Field field = getField(0); 
     layoutChild(field,140, 60); 
     setPositionChild(field, 100,200); 
} 



    public void paint(Graphics graphics) 
    { 
     //Draw the background image and then call paint. 

    // super.paint(graphics); 
     //graphics.clear(); 

     // graphics.setBackgroundColor(0x000000); 
      //graphics.drawBitmap(0, 0, 360, 480, popup, 0, 0); 

      // super.paint(graphics); 
      // graphics.clear();  
     // graphics.drawBitmap(0, 0, 360, 480, popup, 0, 0); 


    }    

    }; 





    ActivityIndicatorView view = new ActivityIndicatorView(Field.USE_ALL_WIDTH); 
    ActivityIndicatorModel model = new ActivityIndicatorModel(); 
    ActivityIndicatorController controller = new ActivityIndicatorController(); 






    boolean notlogged = false; 
    Bitmap popup; 
    SplashScreenPage screen1 = this; 
    private Timer splashTimer = new Timer(); 
    private TimerTask splashTask; 
    int count = 0; 
    int screenWidth = Display.getWidth(); 
    int screenHeight = Display.getHeight(); 
    int yCoord; 
    int xCoord; 
    boolean showSplash = true; 
    boolean splashDisplayed = false; 
    //SplashScreen page is here 
    public SplashScreenPage(Bitmap popup, final int seconds) 
    { 

     view.setController(controller); 
     view.setModel(model); 
     view.setLabel("Loading"); 
     controller.setModel(model); 
     controller.setView(view); 

     model.setController(controller);   

     Bitmap bitmap = Bitmap.getBitmapResource("images.jpeg"); 
     view.createActivityImageField(bitmap, 5, Field.FIELD_BOTTOM); 

     // add(view); 

    add(hfm); 
    hfm.add(view); 
    // add(vfm); 
    // vfm.add(Bitmap.getBitmapResource("splash-blackberry.png")); 






      this.popup = popup; 
      xCoord = (screenWidth - popup.getWidth())/2; 
      yCoord = (screenHeight - popup.getHeight())/2; 

      splashTask = new TimerTask() { 

      public void run() { 

       if (showSplash && !splashDisplayed) { 
        count++; 
        if (count == seconds * 15) { 
         showSplash = false; 
         splashDisplayed = true; 
         splashTimer.cancel(); 
         invalidate(); 


         synchronized (Application.getEventLock()){ 

          UiApplication.getUiApplication().pushScreen(new secondscreen()); 
           notlogged = true; 
          } 

         } 
       } 
      } 
     }; 

     splashTimer.scheduleAtFixedRate(splashTask, 100, 100); 

    } 

    protected void paint(Graphics graphics) { 
     super.paint(graphics); 
     if (showSplash && !splashDisplayed) { 
      graphics.drawBitmap(xCoord, yCoord, popup.getWidth(), popup.getHeight(), popup, 0, 0); 
      // super.paint(graphics); 
      // graphics.clear(); 
     } 
    } 

    protected void onUiEngineAttached(boolean attached) { 
     showSplash = true; 
     invalidate(); 
     super.onUiEngineAttached(attached); 
    } 


    protected boolean navigationMovement(int dx, int dy, int status, int time) { 
     return DismissSplash(); 
    } 

    protected boolean navigationClick(int status, int time) { 
     return DismissSplash(); 
    } 

     protected boolean keyChar(char c, int status, int time) { 
     return DismissSplash(); 
    } 

    private boolean DismissSplash() { 
     if (showSplash) { 
      showSplash = false; 
      splashDisplayed = true; 
      invalidate(); 
      return true; 
     }else{ 
      return false; 
     } 
    } 

    public void onExposed() { 
      if(notlogged) 
      UiApplication.getUiApplication().popScreen(this); 
     } 
} 

回答

0

在你Horizo​​ntalFieldManager要添加视图,你需要确保你在呼唤super.paint(),因为它被称为subpaint(),它会告诉其子字段(在这种情况下查看)来绘制自己。我看到你已经注释掉了,所以你可能已经搞乱了。此外,请确保在调用super.paint()之前进行背景绘画,以免用自己的绘画掩盖ActivityIndi​​catorView。

是否有可能通过并清理代码(将注释掉的代码除去并不重要),直到您希望它能够正常工作的程度,因此更容易区分“尝试任何你可以“编码”和“工作”的代码。

+0

可以请你在上面的代码中展示如何使用subpaint方法,以便我可以在saplash屏幕上显示我的活动indiactor。在此先感谢,,,, – 2011-04-14 11:19:34

+0

subpaint()只是通过子字段并调用paintChild()。如果您从绘画调用中调用super.subpaint(),则不必实际执行它。 – jprofitt 2011-04-14 13:02:08