Android ExplosionField在github上的项目主页是:https://github.com/tyrantgit/ExplosionField
效果如图:
- public class MainActivity extends Activity {
- private ExplosionField mExplosionField;
- private ImageView image;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // 先初始化载入ExplosionField
- mExplosionField = ExplosionField.attach2Window(this);
- image = (ImageView) findViewById(R.id.image);
- image.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // 开始执行动画...
- mExplosionField.explode(v);
- // ExplosionField.explode后,父布局中虽看不到ImageView,但ImageView所占据的位置还会响应事件.
- // 如果想屏蔽此ImageView出现,则:
- image.setVisibility(View.GONE);
- }
- });
- }
- }
MainActivity.java需要的布局文件activiy_main.xml,很简单的一个ImageView:
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:padding="10dip" >
- <ImageView
- android:id="@+id/image"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#c62828"
- android:src="@drawable/ic_launcher" />
- </LinearLayout>