2009-09-30 13 views
7

यह एक क्षेत्र के भीतर कुछ एनीमेशन दिखाना आसान है - BitmapField या स्क्रीन:
[ब्लैकबेरी - पृष्ठभूमि छवि/एनीमेशन रिम ओएस 4.5.0] [1]ब्लैकबेरी - फ़ील्ड लेआउट एनीमेशन

लेकिन क्या आप करने की आवश्यकता है फ़ील्ड, सिर्फ छवियों को नहीं ले जाएं?

किया जा सकता है:

  • खेल कार्यप्रवाह कार्यक्षमता, शतरंज की तरह, पहेली आदि
  • आवेदन उपयोगकर्ता परिभाषित लेआउट, जैसे गूगल गैजेट में
  • बढ़ाया जीयूआई एनीमेशन प्रभाव

तो , मैं इस कार्य में अपनी समाप्ति का आदान-प्रदान करना चाहता हूं, दूसरी तरफ, मैं किसी अन्य संभावनाओं और सुझावों के बारे में जानना चाहता हूं।

+0

मैं अपने पद से चित्रों को निकालने का था, क्योंकि ImageShack उन्हें नष्ट कर दिया और जगह ले ली है उन्हें विज्ञापन के साथ। अधिक जानकारी के लिए http://meta.stackexchange.com/q/263771/215468 देखें। यदि संभव हो, तो आपके लिए उन्हें फिर से अपलोड करना बहुत अच्छा होगा। धन्यवाद! – Undo

उत्तर

12

इस आशय आसानी से कस्टम लेआउट से हासिल किया जा सकता है:

class AnimatedManager extends Manager { 
    int ANIMATION_NONE = 0; 
    int ANIMATION_CROSS_FLY = 1; 
    boolean mAnimationStart = false; 
    Bitmap mBmpBNormal = Bitmap.getBitmapResource("blue_normal.png"); 
    Bitmap mBmpBFocused = Bitmap.getBitmapResource("blue_focused.png"); 
    Bitmap mBmpRNormal = Bitmap.getBitmapResource("red_normal.png"); 
    Bitmap mBmpRFocused = Bitmap.getBitmapResource("red_focused.png"); 
    Bitmap mBmpYNormal = Bitmap.getBitmapResource("yellow_normal.png"); 
    Bitmap mBmpYFocused = Bitmap.getBitmapResource("yellow_focused.png"); 
    Bitmap mBmpGNormal = Bitmap.getBitmapResource("green_normal.png"); 
    Bitmap mBmpGFocused = Bitmap.getBitmapResource("green_focused.png"); 
    int[] width = null; 
    int[] height = null; 
    int[] xPos = null; 
    int[] yPos = null; 
    BitmapButtonField mBButton = new BitmapButtonField(mBmpBNormal, 
      mBmpBFocused); 
    BitmapButtonField mRButton = new BitmapButtonField(mBmpRNormal, 
      mBmpRFocused); 
    BitmapButtonField mYButton = new BitmapButtonField(mBmpYNormal, 
      mBmpYFocused); 
    BitmapButtonField mGButton = new BitmapButtonField(mBmpGNormal, 
      mBmpGFocused); 

    public AnimatedManager() { 
     super(USE_ALL_HEIGHT | USE_ALL_WIDTH); 
     add(mBButton); 
     add(mRButton); 
     add(mYButton); 
     add(mGButton); 
     width = new int[] { mBButton.getPreferredWidth(), 
       mRButton.getPreferredWidth(), 
       mYButton.getPreferredWidth(), 
       mGButton.getPreferredWidth() }; 

     height = new int[] { mBButton.getPreferredHeight(), 
       mRButton.getPreferredHeight(), 
       mYButton.getPreferredHeight(), 
       mGButton.getPreferredHeight() }; 

     xPos = new int[] { 0, getPreferredWidth() - width[1], 0, 
       getPreferredWidth() - width[3] }; 
     yPos = new int[] { 0, 0, getPreferredHeight() - height[2], 
       getPreferredHeight() - height[3] }; 

     Timer timer = new Timer(); 
     timer.schedule(mAnimationTask, 0, 100); 
    } 

    TimerTask mAnimationTask = new TimerTask() { 
     public void run() { 
      UiApplication.getUiApplication().invokeLater(new Runnable() { 
       public void run() { 
        updateLayout(); 
       }; 
      }); 
     }; 
    }; 

    MenuItem mAnimationMenuItem = new MenuItem("Start", 0, 0) { 
     public void run() { 
      mAnimationStart = true; 
     }; 
    }; 

    protected void makeMenu(Menu menu, int instance) { 
     super.makeMenu(menu, instance); 
     menu.add(mAnimationMenuItem); 
    } 

    public int getPreferredHeight() { 
     return Display.getHeight(); 
    } 

    public int getPreferredWidth() { 
     return Display.getWidth(); 
    } 

    protected void sublayout(int width, int height) { 
     width = getPreferredWidth(); 
     height = getPreferredHeight(); 

     if (getFieldCount() > 3) { 
      Field first = getField(0); 
      Field second = getField(1); 
      Field third = getField(2); 
      Field fourth = getField(3); 

      layoutChild(first, this.width[0], this.height[0]); 
      layoutChild(second, this.width[1], this.height[1]); 
      layoutChild(third, this.width[2], this.height[2]); 
      layoutChild(fourth, this.width[3], this.height[3]); 

      if (mAnimationStart) { 
       boolean anim1 = performLayoutAnimation(0, 
         width - this.width[0], 
         height - this.height[0]); 
       boolean anim2 = performLayoutAnimation(1, 0, 
         height - this.height[1]); 
       boolean anim3 = performLayoutAnimation(2, 
         width - this.width[2], 0); 
       boolean anim4 = performLayoutAnimation(3, 0, 0); 
       mAnimationStart = anim1 || anim2 || anim3 || anim4; 
      } 
      setPositionChild(first, xPos[0], yPos[0]); 
      setPositionChild(second, xPos[1], yPos[1]); 
      setPositionChild(third, xPos[2], yPos[2]); 
      setPositionChild(fourth, xPos[3], yPos[3]); 

     } 

     setExtent(width, height); 
    } 

    boolean performLayoutAnimation(int fieldIndex, int x, int y) { 

     boolean result = false; 
     if (xPos[fieldIndex] > x) { 
      xPos[fieldIndex] -= 2; 
      result = true; 
     } else if (xPos[fieldIndex] < x) { 
      xPos[fieldIndex] += 2; 
      result = true; 
     } 

     if (yPos[fieldIndex] > y) { 
      yPos[fieldIndex] -= 1; 
      result = true; 
     } else if (yPos[fieldIndex] < y) { 
      yPos[fieldIndex] += 1; 
      result = true; 
     } 
     return result; 
    } 
} 

BitmapButtonField वर्ग मैं का उपयोग किया है:

class BitmapButtonField extends ButtonField { 
    Bitmap mNormal; 
    Bitmap mFocused; 

    int mWidth; 
    int mHeight; 

    public BitmapButtonField(Bitmap normal, Bitmap focused) { 
     super(CONSUME_CLICK); 
     mNormal = normal; 
     mFocused = focused; 
     mWidth = mNormal.getWidth(); 
     mHeight = mNormal.getHeight(); 
     setMargin(0, 0, 0, 0); 
     setPadding(0, 0, 0, 0); 
     setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0))); 
     setBorder(VISUAL_STATE_ACTIVE, BorderFactory 
       .createSimpleBorder(new XYEdges(0, 0, 0, 0))); 
    } 

    protected void paint(Graphics graphics) { 
     Bitmap bitmap = null; 
     switch (getVisualState()) { 
     case VISUAL_STATE_NORMAL: 
      bitmap = mNormal; 
      break; 
     case VISUAL_STATE_FOCUS: 
      bitmap = mFocused; 
      break; 
     case VISUAL_STATE_ACTIVE: 
      bitmap = mFocused; 
      break; 
     default: 
      bitmap = mNormal; 
     } 
     graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(), 
       bitmap, 0, 0); 
    } 

    public int getPreferredWidth() { 
     return mWidth; 
    } 

    public int getPreferredHeight() { 
     return mHeight; 
    } 

    protected void layout(int width, int height) { 
     setExtent(mWidth, mHeight); 
    } 

    protected void applyTheme(Graphics arg0, boolean arg1) { 

    } 
} 
संबंधित मुद्दे