为多个设备的Andr​​oid animationing意见 [英] android animationing views for multiple devices

查看:241
本文介绍了为多个设备的Andr​​oid animationing意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的一个小游戏,如果你得到正确的气球漂浮在屏幕中,气球被2 ObjectAnimators在动画集中移动的看法,我的主要调试设备,它工作正常,但在其他设备(包括平板电脑),它看起来aweful值是所有的地方和意见剧烈摇摆从一个侧面下。
 这里是即时通讯做的一个片段:

I have a small game in my application, if you get something right balloons float up the screen, the balloons are views moved by 2 ObjectAnimators in an animation set, and on my main debugging device it works fine but on other devices (including tablets) it looks aweful the values are all over the place and the views violently sway from one side to the next. here is a snippet of what im doing:

// 2平方米的气球漂浮

//2 square balloons floating

            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();

//正确的气球

//right balloon

            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();

//气球动画结束

//balloon animation end

            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

香港专业教育学院读,我可以在正确的方向上使用的一小部分,而不是明确的价值观,任何人可以帮助我走出这个或点,
任何和所有的建议表示欢迎,非常感谢

ive read i can use a fraction rather than explicit values, can anybody help me out with this or point in the right direction, any and all suggestions welcome, many thanks

推荐答案

我猜你的问题是在参数使用的是(硬编码),如:

I guess your problem is in parameters you are using (hardcoding) like:

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

由于这些值仅用于设备(​​屏幕实际上)你正在测试良好。其他设备与其他分辨率其他屏幕,你应该考虑一下。你也应该从DP到像素也许钙值。什么是500和2000年实际?如果它的像素则最有可能这就是这个问题。结果
看看这里(DP会PX):结果
<一href=\"http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-in-android/2025541#2025541\">Difference PX之间,DP,倾角和SP在Android的?结果
安卓:?'DP'到'像素'换算

这篇关于为多个设备的Andr​​oid animationing意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆