0

画像ビューでフレームごとのアニメーションを適用しました。フレームごとに2つの画像を使用するだけです

main.java

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ImageView iv = (ImageView) findViewById( R.id.imageView1);

    iv.setBackgroundResource(R.anim.animation);
    AnimationDrawable ac= (AnimationDrawable) iv.getBackground();
    ac.start();

    //ac.stop();
if(ac.isRunning()==false){
        iv.setVisibility(View.INVISIBLE);
    }
        }

アニメーション.xml

<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/image1" android:duration="1000"/>
<item android:drawable="@drawable/image2" android:duration="1000"/>
 </animation-list>

activity_main.xml(レイアウト)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true" />

   </RelativeLayout>

また、このアニメーションを停止する場所がわかりません。2 つの画像がアニメーション化された後に画像ビューを非表示にして、後でアニメーションを再開する必要があります。

私は広告画像に取り組んでいます。そのため、画像を短時間表示する必要があり、後で再起動します。

誰かがこの解決策を知っていれば。私を助けてください。

4

1 に答える 1

0

ImageView iv = (ImageView) findViewById( R.id.imageView1);

iv.setBackgroundResource(R.anim.animation);
AnimationDrawable ac= (AnimationDrawable) iv.getBackground();
ac.start();

アニメーションの最後の項目として空の画像を配置するだけです。

    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
     android:oneshot="true"
 >
 <item android:drawable="@drawable/image1" android:duration="1000"/>
 <item android:drawable="@drawable/image2" android:duration="1000"/>
  <item android:drawable="@drawable/dummy" android:duration="1000"/>

     </animation-list>

ワンショット=真。

を再起動するには、onClick メソッドを呼び出して、次のように start を再度呼び出すことができます。

    btn1.setOnClickListener(new View.OnClickListener() {
      @Override
        public void onClick(View view) {

            ImageView iv = (ImageView) findViewById( R.id.imageView1);

               iv.setBackgroundResource(R.anim.animation);
               AnimationDrawable ac= (AnimationDrawable) iv.getBackground();
              ac.start();

        }
于 2013-03-04T11:32:47.240 に答える