2012-04-17 14 views
0

画面の異なる場所に4つの画像が配置されています。今度は、画面の幅と高さに合わせてクリックしてアニメートします。クリックすると画面の他のコンテンツがフェードアウトされます。私はXMLが間違っていることを知っていると私はコーディングに余分な何かをする必要があるため、現在、私は彼らにAndroid Animate Scale画面の幅と高さに合わせる画像

zoom_image.xmlは、上記のコード

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/linear_interpolator"> 
    <scale android:fromXScale="0.0" android:fromYScale="0.0" 
      android:toXScale="1.0" android:toYScale="1.0" 
      android:duration="700" android:fillBefore="false" /> 
    <translate android:fromXDelta="0.0" android:fromYDelta="1.0" 
      android:duration="700" /> 
</set> 

あるとして活躍されていない

Animation logoMoveAnimation = AnimationUtils.loadAnimation(this, R.anim.zoom_image); 
view.startAnimation(logoMoveAnimation); 

を拡張するには、次のコードを使用しています。

+0

誰に任意のアイデアを使用して終了? –

答えて

3

私は、次のコード

final int initialWidth = v.getWidth(); 
     final int initialHeight = v.getHeight(); 
     Log.v("WIDTH_", Integer.toString(initialWidth)); 
     Log.v("HEIGHT_", Integer.toString(initialHeight)); 
     DisplayMetrics displaymetrics = new DisplayMetrics(); 
     getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 
     final int finalHeight = displaymetrics.heightPixels; 
     final int finalWidth = displaymetrics.widthPixels; 
     Log.v("WIDTH_F", Integer.toString(finalWidth)); 
     Log.v("HEIGHT_F", Integer.toString(finalHeight)); 
     final int animationDuration = 1500; 
     final float stepX = (float)((float)(finalWidth - initialWidth))/animationDuration; 
     final float stepY = (float)((float)(finalHeight - initialHeight))/animationDuration; 
     Log.v("stepX", Float.toString(stepX)); 
     Log.v("stepY", Float.toString(stepY)); 
     final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
      RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
     layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
    Animation a = new Animation() { 
       @Override 
       protected void applyTransformation(float interpolatedTime, Transformation t) { 
        int newWidth, newHeight; 
        Log.v("INTERPOLATION_T", Float.toString(interpolatedTime)); 
        newWidth = (int)Math.ceil((initialWidth + stepX*interpolatedTime*animationDuration)); 
        newHeight = (int)Math.ceil((initialHeight + stepY*interpolatedTime*animationDuration));        
        if(v.getTag().toString().equals("1")) { 
         //layoutParams.setMargins(0, (int)-interpolatedTime*initialHeight, 0, 0); 
        } 
        else if(v.getTag().toString().equals("2")) { 
         layoutParams.addRule(RelativeLayout.RIGHT_OF, R.id.separator1); 
         //layoutParams.setMargins((int)-interpolatedTime*initialWidth, (int)-interpolatedTime*initialHeight, 0, 0); 
        } 
        else if(v.getTag().toString().equals("3")) { 
         layoutParams.addRule(RelativeLayout.RIGHT_OF, R.id.separator2); 
         //layoutParams.setMargins((int)-interpolatedTime*initialWidth, (int)-interpolatedTime*initialHeight, 0, 0); 
        } 
        else if(v.getTag().toString().equals("4")) { 
         layoutParams.addRule(RelativeLayout.RIGHT_OF, R.id.separator3); 
         //layoutParams.setMargins((int)-interpolatedTime*initialWidth, (int)-interpolatedTime*initialHeight, 0, 0); 
        } 
        v.setLayoutParams(layoutParams); 
        v.getLayoutParams().height = newHeight; 
        v.getLayoutParams().width = newWidth; 
        v.requestLayout(); 
       } 
       @Override 
       public boolean willChangeBounds() { 
        return true; 
       } 
      }; 

      a.setInterpolator(new LinearInterpolator()); 
      a.setDuration(animationDuration); 
      a.setFillAfter(true); 
      v.startAnimation(a); 
+0

このコードを使ってみましたが、アニメーションがスムーズではありません。あなたはどんな仕事でも見つけることができましたか? –

0

はそれを試してみてください -

ImageView view = <from xml>; 
view.startAnimation(logoMoveAnimation); 

とImageViewののXMLプロパティでscaletype = fitxyを設定します。

関連する問題