13

レイヤーリストオブジェクトがあり、2 つの画像が含まれています。1 つは背景で、もう 1 つは背景画像の上部で回転する回転ディスク画像です。つまり、このレイヤーリストをリニアレイアウトの背景として使用し、レイヤーリストの「disk_bg」アイテムのみをアニメーション化したいと考えています。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/
android">
       <item android:drawable="@drawable/player_bg" />

       <item  android:top="166dp" >
             <bitmap  android:id="@+id/disk_bg" android:src="@drawable/cd"
       android:gravity="center" />
       </item>

このレイヤーリストをレイアウトの背景として使用しています。アプリケーションで disk_bg レイヤーをアニメーション化する方法を知っていますか?

私を助けてくれませんか、どうもありがとう〜

私の質問がわかりませんか?またはそれを行う方法はありませんか?

4

1 に答える 1

2

まず、フレームを設定する 2 つ (またはそれ以上) のレイヤー リスト リソース、つまり *layer_frame1.xml* と *layer_frame2.xml* を作成します。あなたの場合、ディスク項目の android:top を変更するとしましょう。

次に、フレームのタイミングと順序を設定するアニメーション リスト リソースを作成します。

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

    <item
        android:drawable="@drawable/layer_frame1"
        android:duration="100"/>
    <item
        android:drawable="@drawable/layer_frame2"
        android:duration="100"/>

</animation-list>

*drawable/player_animation.xml* などのファイルに保存し、ビューの背景として設定します。

<View
        android:id="@+id/animation_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/player_animation" />

最後に、アニメーションをいつ開始するかをコードで指定します。

 ((AnimationDrawable)findViewById(R.id.animation_test).getBackground()).start();

onCreate()メソッド内でアニメーションを開始しないように注意してください。

于 2012-09-23T10:57:10.190 に答える