xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
>
、布局文件中:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/list"
/>
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="31dp"
android:layout_marginTop="18dp"
android:text="停止" />
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_marginRight="63dp"
android:layout_toLeftOf="@+id/button1"
android:text="开始" />
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_alignParentLeft="true"
android:text="吟唱" />
package com.example.domeimage;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.AvoidXfermode;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView animationIV;
private AnimationDrawable animationDrawable;
private Button button,button2,button3;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animationIV=(ImageView) findViewById(R.id.image);
button=(Button) findViewById(R.id.button1);
button2=(Button) findViewById(R.id.button2);
button3=(Button) findViewById(R.id.button3);
// animationIV.setImageResource(R.drawable.list);
animationDrawable = (AnimationDrawable) animationIV.getDrawable();
animationDrawable.start();
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
animationDrawable.stop();
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
animationDrawable.start();
}
});
button3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
animationIV.setVisibility(View.GONE);
}
});
}
}