私は、いくつかの画像を持つ画面を持っていて、そのうちの1つには、肖像画の中ですばらしく見える素敵なアニメーションがあります。肖像画で肖像画と風景のようなアンドロイドのアニメーションをオフセンターで回転させるにはどうしたらいいですか?
恐ろしいアニメーション - rotate_anim_port.png - HERE
にそれは風景の中にとても素晴らしい見ていません。
風景のアニメーション - rotate_anim_land.png - 上記。
私は同じサイズの描画可能なリソースを持つ複数のイメージビューをフレームビューに積み重ねて、それらをすべて同じ位置に保ちますが、どのサイズにもスケーリングできるため、オフセンターローテーションアニメーションを実装していますフレームビューはです。
RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue)
がpivotValuesを基準にしているビューが、ビュー内のイメージと同じサイズではないため、表示が悪くなります。肖像画の場合、イメージはビューとほぼ同じサイズですが、ランドスケープではその違いが明らかです。
私は、内部でビューと描画されたイメージの両方からポジションを取得して、正しいpivotValuesを計算してコードを渡すことに失敗しました。レイアウトここ
package com.namespace;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
public class AnimationDemoActivity extends Activity {
// piviotValues if the view is the exact size of the drawable.
final float pivotXType = 0.3280274656679151f;
final float pivotYValue = 0.5060137457044674f;
private Handler mHandler = new Handler();
ImageView outside, inside;
RotateAnimation anim, anim2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
outside = (ImageView) findViewById(R.id.imageView1);
inside = (ImageView) findViewById(R.id.imageView2);
outside.setVisibility(ImageView.INVISIBLE);
inside.setVisibility(ImageView.INVISIBLE);
// somewhere in here, code to recalculate pivotValues to adjust for the
// size of the actual view the images are inside of
anim = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF,
pivotXType, Animation.RELATIVE_TO_SELF, pivotYValue);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(2000);
anim2 = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF,
pivotXType, Animation.RELATIVE_TO_SELF, pivotYValue);
anim2.setInterpolator(new LinearInterpolator());
anim2.setRepeatCount(Animation.INFINITE);
anim2.setDuration(750);
mHandler.postDelayed(doRotation, 2500);
}
private Runnable doRotation = new Runnable() {
public void run() {
outside.setVisibility(ImageView.VISIBLE);
inside.setVisibility(ImageView.VISIBLE);
outside.startAnimation(anim);
inside.startAnimation(anim2);
}
};
}
とされています: - AnimationDemo.apkとzip形式のプロジェクト - AnimationDemo.zip
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
android:padding="10sp" >
<ImageSwitcher
android:id="@+id/imageSwitcher1"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center" >
</ImageSwitcher>
<ImageSwitcher
android:id="@+id/imageSwitcher2"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center" >
</ImageSwitcher>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dwdg_outside_arrow" >
</ImageView>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dwdg_inside_arrow" >
</ImageView>
</FrameLayout>
</LinearLayout>
Hereが実行可能であるAPKここ
は、活動のためのコードです私はこのようにして狂ってる?私は完全に何かを見過ごしていますか?何ですか?
どのように** pivotXType **と** pivotYValue **を計算しましたか? – AnujAroshA
これは、バックグラウンドドロウブルに関連してオーバーレイの中心点の位置を指定します。 pivotYValueは、0.5060137457044674f、つまりドロワブルの高さの50%ish、つまり中心です。 pivotXTypeはドロウアブルの幅の33%のところにあり、したがってセンターの左にあります。あなたがセンターの右にそれを望むなら、あなたはそれを66%にするでしょう。私はそれをしなければなりませんでした。なぜなら、いったん画面上にピクセルとして置かれると、ドロアブルやオーバーレイがどのサイズになるのかを決して正確に知ることができないからです。 – peetsnack
私がしたことは、生のイメージファイルで自分の背景の上でアニメーションを回転させたいと思ったピクセル中心点を見つけてから、全体のイメージのピクセルサイズに対する比率を取得することでした。 – peetsnack