2013-09-05 52 views
0

像素密度我有一个下面的动画:的Android爪哇确定在代码

ImageView fallingLeave = (ImageView) rootView.findViewById(R.id.lemonpiece1_large); 
        mButtonProxy = AnimatorProxy.wrap(fallingLeave); 

        // Set up the path we're animating along 
        AnimatorPath path = new AnimatorPath(); 
        path.moveTo(0,0); 
        path.curveTo(0, 0, 0 , 80, -80, 70); 
        fallingLeave.setRotation(80); 
        path.curveTo(-80, 70, -80, 120, 80, 140); 
        path.curveTo(80, 140, 80, 190, -80, 210); 


        // Set up the animation 
        final ObjectAnimator anim = ObjectAnimator.ofObject(this, "buttonLoc", 
          new PathEvaluator(), path.getPoints().toArray()); 
        anim.setDuration(2000); 


        anim.start(); 

问题是,路径被设定在固定的像素。我想要做的是设置独立的路径像素。任何想法如何实现?

我试图将变量链接到dimensions.xml,但它没有工作,我宁愿用像素密度比MULTIPLY像素路径,但我不知道是否有函数可以返回密度值设备的比率。

任何帮助表示赞赏。

+0

'[Context.getResources.getDimensionsPixelSize()](http://developer.android.com/reference/android/content/res/Resources.html#getDimensionPixelSize(int))'从未失败过。也许你可以详细说明为什么这不适合你。但是这是遵循的方法,因为它可以更好地配置为以这种方式工作。 – gunar

回答

0

Here's的答案,可能会有所帮助。 从答案那里看起来这是你要找的

DisplayMetrics dm = context.getResources().getDisplayMetrics(); 
int densityDpi = dm.densityDpi; 
+0

谢谢,这是我一直在寻找的 – Jenda

0
DisplayMetrics dm = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(dm); 

现在使用dm.xdpi()dm.ydpi()获得在X和Y尺寸的像素密度。

0

您可以使用这里找到DisplayMetrics类行:DisplayMetrics

,并使用密度场

的显示器的逻辑密度。这是密度无关像素单位的缩放系数,其中一个DIP在大约160 dpi的屏幕上(例如240x320,1.5“x2”屏幕)上的一个像素,提供系统显示的基线。因此在160dpi的屏幕上,这个密度值将是1;在120 dpi的屏幕上它将是0.75;等等

希望它有帮助。