質問

私はイメージビューとウェブビューのレイアウトを作成しました。ウェブビューがなくなっデフォルトの可視性を持つように設定されています。活性火災がアップそれが最初の画像ビューを表示すると、Webビューは、そのURLをロードし終えたときに、それが目に見えるようにそれ自身をマークし、非表示としてImageViewのがマークされている。

ImageViewのが表示されたら、私はそれがほんの少し追加あか抜けために繰り返し回転したいと思います。

私は、Androidで前にアニメーションをやったことがないと私はインターネットを尋ねられたとき、私は見つかったすべての記事は役立ちませんでした。したがって、私は助けをSOに戻ってきました。

私はこれで始めるのであれば...

    final ImageView splash = (ImageView)findViewById(R.id.splash);

どのように私は繰り返し回転アニメーションを作成し、ImageViewのにそれを適用するのですか?

おかげで再び!

役に立ちましたか?

解決

にピボットポイントを設定、 RotateAnimation に使用あなたの画像の中央ます。

RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);

// Start animating the image
final ImageView splash = (ImageView) findViewById(R.id.splash);
splash.startAnimation(anim);

// Later.. stop the animation
splash.setAnimation(null);

他のヒント

をその中心の周りにイメージを回転する方法:

ImageView view = ... //Initialize ImageView via FindViewById or programatically

RotateAnimation anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

//Setup anim with desired properties
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE); //Repeat animation indefinitely
anim.setDuration(700); //Put desired duration per anim cycle here, in milliseconds

//Start animation
view.startAnimation(anim); 
//Later on, use view.setAnimation(null) to stop it.

これはその中心(幅/高さの0.5又は50%)の周りを回転するように画像を生じさせます。私は絶対ピクセル単位で語っセンターを定義せずに、その中心の周りに画像を回転させることを望む私が持っているとして、Googleからのここに来る、そして将来の読者のためにこれを掲示しています。

あなたは、単に回しアニメーション機能を使用することができます。つまりImageViewの上に、時間の所定量のための特定のアニメーションを、実行します。

Animation rotate = AnimationUtils.loadAnimation([context], R.anim.rotate_picture);
splash.startAnimation(rotate);

次に、あなたの解像度でアニメーションXMLファイルを作成/アニメーションは、コンテンツとrotate_pictureと呼ばれます:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false">

    <rotate 
    android:fromDegrees="0"
    android:toDegrees="360"
    android:duration="5000"
    android:pivotX="50%"
    android:pivotY="50%">
</rotate>
</set>

さて、残念ながら、これは一度だけ実行されます。あなたはそれが待っている間、それはアニメーションを繰り返し行うためにどこかにループが必要になります。私は少し実験して、私のプログラムが無限ループに捕まってしまったので、私はそれに最善の方法のかわかりません。 EDIT:クリストファーの答えは非常に別々のスレッドについての私の悪い提案を削除する、適切にループさせる方法についての情報を提供しています。

一つの方法 - 少したびに、それを回転さNにあなたの画像を分割します。私は5が十分にあると思います。 その後、描画可能で、このようなものを作成する

<animation-list   android:id="@+id/handimation" android:oneshot="false" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/progress1" android:duration="150" />
    <item android:drawable="@drawable/progress2" android:duration="150" />
    <item android:drawable="@drawable/progress3" android:duration="150" />
 </animation-list> 

コード開始

progress.setVisibility(View.VISIBLE);
AnimationDrawable frameAnimation = (AnimationDrawable)progress.getDrawable();
frameAnimation.setCallback(progress);
frameAnimation.setVisible(true, true);

コードストップ

AnimationDrawable frameAnimation = (AnimationDrawable)progress.getDrawable();
frameAnimation.stop();
frameAnimation.setCallback(null);
frameAnimation = null;
progress.setVisibility(View.GONE);

よりここ

imgDics = (ImageView) v.findViewById(R.id.img_player_tab2_dics);
    imgDics.setOnClickListener(onPlayer2Click);
    anim = new RotateAnimation(0f, 360f,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                            0.5f);
    anim.setInterpolator(new LinearInterpolator());
    anim.setRepeatCount(Animation.INFINITE);
    anim.setDuration(4000);

    // Start animating the image
    imgDics.startAnimation(anim);

要素の中に入れます:

android:repeatCount="infinite"

私はあなたはそれが動作しないこと...など.getWidth / 2を使用する場合は、イメージがあるピクセル数を取得し、2で自分自身をそれを分割する必要があり、その後、ちょうどで入力すること、を見出しました最後の2つの引数の数。

ので、あなたの画像を60個の画素に等しくなる120画素の正方形、UR XおよびYによって120画素であったと言います。 ので、あなたのコードでは、あなたが正しいでしょう。

RotateAnimation anim = new RotateAnimation(0f, 350f, 60f, 60f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);

そして今、あなたのイメージは、その中心の周りを旋回します。

確認済みコード:

imageView.setImageResource(R.drawable.ic_arrow_up);

boolean up = true;

if (!up) { 
    up = true; 
    imageView.startAnimation(animate(up)); 
} else { 
    up = false; 
    imageView.startAnimation(animate(up)); 
}

private Animation animate(boolean up) {
    Animation anim = AnimationUtils.loadAnimation(this, up ? R.anim.rotate_up : R.anim.rotate_down);
    anim.setInterpolator(new LinearInterpolator()); // for smooth animation
    return anim;
}

描画可能/ ic_arrow_up.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#3d3d3d"
        android:pathData="M7.41,15.41L12,10.83l4.59,4.58L18,14l-6,-6 -6,6z"/>
</vector>

アニメーション/ rotate_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:fillEnabled="true">
    <rotate
        android:duration="200"
        android:fromDegrees="-180"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="0" />
</set>

アニメーション/ rotate_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:fillEnabled="true">
    <rotate
        android:duration="200"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="180" />
</set>

ハードコード画像境界をしないでください。ただ、使用します:

RotateAnimation anim = new RotateAnimation( fromAngle, toAngle, imageView.getDrawable().getBounds().width()/2, imageView.getDrawable().getBounds().height()/2);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top