2

画面の中央から始まるImageViewをアニメーション化し、画面の上部から10ピクセル上に移動したいと思います。コードでこれをどのように達成できますか?

私が現在行っているのは、画面を別の画像に合わせて、このアニメーション画像をその上に少し配置することですが、高密度の大画面では、同じ距離を維持できないためです。代わりに、上から10px移動したいと思います。

どうすればこれを達成できますか?

これが私のコードです:

//calculate where to put the logo in y-axis depending on screen size
            int coords[] = {0,0};
            logoImageFixed.getLocationOnScreen(coords);
            int y = coords[1];
            int imgFixedHeight = logoImageFixed.getHeight();
            Log.d("daim","height: "+imgFixedHeight);
            float pointY = -(y + 3*imgFixedHeight);

            Animation a = new LogoAnimation(0.0f, 0.0f, 0.0f, pointY);
            a.setFillAfter(true);
            a.setDuration(600);
            a.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {}
                @Override
                public void onAnimationRepeat(Animation animation) {}
                @Override
                public void onAnimationEnd(Animation animation) {
                    logoAnimated = true;
                }
            });
            logoImage.startAnimation(a);
4

1 に答える 1

4

さて、あなたは正しい道を進んでいると思います

int[] coords = {0,0};
logoImage.getLocationOnScreen(coords);
int y = coords[1];

//to top of screen  
TranslateAnimation toTop = new TranslateAnimation(0, 0, 0, -y);
toTop.setDuration(700);
toTop.setFillAfter(true);
logoImage.startAnimation(toTop);

ただし、パディングをさらに10ピクセル追加する場合は、これを行う必要があります

//padding 10 pixels from top    
TranslateAnimation toTop = new TranslateAnimation(0, 0, 0, ((-y) - 10));
toTop.setDuration(700);
toTop.setFillAfter(true);
logoImage.startAnimation(toTop);
于 2012-10-01T05:26:05.747 に答える