Android ExplosionField在github上的项目主页是:https://github.com/tyrantgit/ExplosionField
Android ExplosionField使用简单,几乎可以针对任意的view制造出上图所示效果。
ExplosionField使用之前先需要到其github上的主页将其拖下来,导入作为lib使用。
运行效果图:
代码如下:
1 package com.lixu.baozha; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.view.View.OnClickListener; 7 import android.widget.Button; 8 import android.widget.ImageView; 9 import android.widget.Toast; 10 import tyrantgit.explosionfield.ExplosionField; 11 12 public class MainActivity extends Activity implements OnClickListener { 13 private ImageView iv; 14 private ImageView iv1; 15 private ImageView iv2; 16 private ImageView iv3; 17 private ExplosionField mExplosionField; 18 19 @Override 20 protected void onCreate(Bundle savedInstanceState) { 21 super.onCreate(savedInstanceState); 22 setContentView(R.layout.activity_main); 23 24 mExplosionField = ExplosionField.attach2Window(this); 25 26 iv = (ImageView) findViewById(R.id.aixin); 27 iv1 = (ImageView) findViewById(R.id.aixin1); 28 iv2 = (ImageView) findViewById(R.id.aixin2); 29 iv3 = (ImageView) findViewById(R.id.aixin3); 30 31 iv.setOnClickListener(this); 32 iv1.setOnClickListener(this); 33 iv2.setOnClickListener(this); 34 iv3.setOnClickListener(this); 35 36 Button btn = (Button) findViewById(R.id.btn); 37 btn.setOnClickListener(this); 38 39 } 40 41 @Override 42 public void onClick(View v) { 43 switch (v.getId()) { 44 case R.id.aixin: 45 mExplosionField.explode(v); 46 47 Toast.makeText(getApplicationContext(), "心碎了!!", 0).show(); 48 49 break; 50 case R.id.aixin1: 51 mExplosionField.explode(v); 52 53 Toast.makeText(getApplicationContext(), "心碎了!!", 0).show(); 54 55 break; 56 case R.id.aixin2: 57 mExplosionField.explode(v); 58 59 Toast.makeText(getApplicationContext(), "心碎了!!", 0).show(); 60 61 break; 62 case R.id.aixin3: 63 mExplosionField.explode(v); 64 65 Toast.makeText(getApplicationContext(), "心碎了!!", 0).show(); 66 67 break; 68 69 case R.id.btn: 70 71 mExplosionField.explode(iv); 72 mExplosionField.explode(iv1); 73 mExplosionField.explode(iv2); 74 mExplosionField.explode(iv3); 75 76 Toast.makeText(getApplicationContext(), "天女散花!", 0).show(); 77 78 break; 79 80 default: 81 break; 82 } 83 84 } 85 }
xml文件:
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:id="@+id/LinearLayout1" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 tools:context="com.lixu.baozha.MainActivity" > 7 8 9 <LinearLayout 10 android:id="@+id/linearLayout2" 11 android:layout_width="match_parent" 12 android:layout_height="200dp" 13 android:layout_alignParentLeft="true" 14 android:layout_alignParentTop="true" > 15 16 <ImageView 17 android:id="@+id/aixin" 18 android:layout_width="wrap_content" 19 android:layout_height="80dp" 20 android:layout_weight="1" 21 android:background="@drawable/aixin" /> 22 23 <ImageView 24 android:id="@+id/aixin1" 25 android:layout_width="wrap_content" 26 android:layout_height="80dp" 27 android:layout_weight="1" 28 android:background="@drawable/aixin" /> 29 30 <ImageView 31 android:id="@+id/aixin2" 32 android:layout_width="wrap_content" 33 android:layout_height="80dp" 34 android:layout_weight="1" 35 android:background="@drawable/aixin" /> 36 37 <ImageView 38 android:id="@+id/aixin3" 39 android:layout_width="wrap_content" 40 android:layout_height="80dp" 41 android:layout_weight="1" 42 android:background="@drawable/aixin" /> 43 </LinearLayout> 44 45 <Button 46 android:id="@+id/btn" 47 android:layout_width="wrap_content" 48 android:layout_height="wrap_content" 49 android:layout_below="@+id/linearLayout2" 50 android:layout_centerHorizontal="true" 51 android:layout_marginTop="76dp" 52 android:text="开始" /> 53 54 </RelativeLayout>