2015-04-01 43 views
0

我在我的應用程序中有一個小遊戲,如果你有正確的氣球浮起屏幕,氣球是動畫設置中的2 ObjectAnimators移動的視圖,並在我的主調試設備上工作很好,但在其他設備(包括平板電腦)上,它看起來很有價值,各處都有價值觀,觀點從一邊到另一邊劇烈搖擺。 這裏是什麼即時通訊做的一個片段:Android動畫視圖的多個設備

// 2平方米的氣球漂浮

  sb = (ImageView)findViewById(R.id.squareballoon); 
      sb.setVisibility(View.VISIBLE); 

      sb2 = (ImageView)findViewById(R.id.squareballoon2); 
      sb2.setVisibility(View.VISIBLE); 

      sp.play(inflate, 1, 1, 0, 0, 1); 

//左氣球

  ObjectAnimator sqbalAnim3 = ObjectAnimator.ofFloat(sb,"x",-500,500); 
      sqbalAnim3.setDuration(700); 
      sqbalAnim3.setRepeatCount(5); 
      sqbalAnim3.setRepeatMode(ValueAnimator.REVERSE); 

      ObjectAnimator sqbalAnim = ObjectAnimator.ofFloat(sb,"y",2000,-1800); 
      sqbalAnim.setDuration(3000); 
      sqbalAnim.setRepeatMode(ValueAnimator.RESTART); 

      AnimatorSet animSetXY = new AnimatorSet(); 
      animSetXY.playTogether(sqbalAnim, sqbalAnim3); 
      animSetXY.start(); 

//右氣球

  ObjectAnimator sqbalAnim4 = ObjectAnimator.ofFloat(findViewById(R.id.squareballoon2),"x",-1500,-500); 

      sqbalAnim4.setDuration(700); 
      sqbalAnim4.setRepeatCount(5); 
      sqbalAnim4.setRepeatMode(ValueAnimator.REVERSE); 

      ObjectAnimator sqbal2Anim = ObjectAnimator.ofFloat(findViewById(R.id.squareballoon2),"y",1800,-1800); 
      sqbal2Anim.setDuration(3000); 
      sqbal2Anim.setRepeatMode(ValueAnimator.RESTART); 


      AnimatorSet animSetXY2 = new AnimatorSet(); 
      animSetXY2.playTogether(sqbal2Anim,sqbalAnim4); 
      animSetXY2.start(); 

//氣球動畫結束

  animSetXY2.addListener(new AnimatorListenerAdapter() { 
       @Override 
       public void onAnimationEnd(Animator animation) { 
        super.onAnimationEnd(animation); 

          sp.play(dropSound,1,1,0,0,1); 
          sb.setBackgroundResource(R.drawable.burst); 
          pop = (AnimationDrawable) sb.getBackground(); 
          pop.start(); 
          sb2.setBackgroundResource(R.drawable.burst); 
          pop = (AnimationDrawable) sb2.getBackground(); 
          pop.start(); 

       } 
      }); 
      return true;} 

     //end of square balloons 

香港專業教育學院讀,我可以使用一小部分,而不是明確的價值觀,任何人可以幫助我這個或點在正確的方向, 任何和所有的建議表示歡迎,非常感謝

回答

1

我猜你的問題是在您正在使用的參數(硬編碼)如下:

ObjectAnimator.ofFloat(sb,"x",-500,500); 
ObjectAnimator.ofFloat(sb,"y",2000,-1800); 

由於這些值僅適用於您正在測試的設備(屏幕實際)。其他設備有其他屏幕與其他分辨率,你應該考慮它。你也許應該計算從dp到像素的值。實際上500和2000是什麼?如果它的像素很可能就是這個問題。
看看這裏(DP會PX):
What is the difference between "px", "dp", "dip" and "sp" on Android?
Android: 'dp' to 'px' conversion?

+0

你在騙我!我已經閱讀過之前的差異,但出於不同的原因,我還是比較新的,所以我應該只使用dp或px非常感謝你 – martinseal1987 2015-04-01 19:00:22