images/loading.gif' data-original="http://images2015.cnblogs.com/blog/822717/201511/822717-20151127113748156-10393723.gif" />
这个很有趣的指标通过AnimCheckBox实现,下载地址:https://github.com/lguipeng/AnimCheckBox
代码:
activity_main.
1 <RelativeLayout ="http://schemas.android.com/apk/res/android" 2 ="http://schemas.android.com/tools" 3 ="http://schemas.android.com/apk/res-auto" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" > 6 7 <!-- app:circle_color 点击后的背景颜色设置 --> 8 <!-- app:stroke_color 线条颜色和点击后的勾勾颜色设置 --> 9 <!-- app:stroke_width 线条宽度设置 -->10 11 <com.github.lguipeng.library.animcheckbox.AnimCheckBox12 android:id="@+id/checkBox"13 android:layout_width="80dp"14 android:layout_height="80dp"15 android:layout_centerInParent="true"16 app:circle_color="#1976D2"17 app:stroke_width="4dp" />18 19 <Button20 android:id="@+id/button"21 android:layout_width="wrap_content"22 android:layout_height="wrap_content"23 android:layout_below="@id/checkBox"24 android:layout_centerHorizontal="true"25 android:paddingTop="20dp"26 android:text="button" />27 28 </RelativeLayout>
MainActivity.java:
1 package com.zzw.testanimcheckbox; 2 3 import com.github.lguipeng.library.animcheckbox.AnimCheckBox; 4 import com.github.lguipeng.library.animcheckbox.AnimCheckBox.OnCheckedChangeListener; 5 6 import android.app.Activity; 7 import android.os.Bundle; 8 import android.view.View; 9 import android.view.View.OnClickListener;10 import android.widget.Toast;11 12 public class MainActivity extends Activity {13 private boolean temp=true;14 private AnimCheckBox checkBox;15 @Override16 protected void onCreate(Bundle savedInstanceState) {17 super.onCreate(savedInstanceState);18 setContentView(R.layout.activity_main);19 20 checkBox = (AnimCheckBox) findViewById(R.id.checkBox);21 // 设置默认显示为勾还是圈22 checkBox.setChecked(temp);23 24 checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {25 @Override26 public void onChange(boolean checked) {27 if(checked==true){28 Toast.makeText(getApplicationContext(), "true", 0).show();29 }else{30 Toast.makeText(getApplicationContext(), "false", 0).show();31 }32 }33 });34 findViewById(R.id.button).setOnClickListener(new OnClickListener() {35 36 @Override37 public void onClick(View v) {38 if(temp==true){39 temp=false;40 }else{41 temp=true;42 }43 //当点击按钮判断值temp变化了的时候,checkBox的随之变化,并且显示出动画效果,44 //后面如果是false的话,动画就不会显示,并且画面不会出现变化45 checkBox.setChecked(temp,true);46 }47 });48 }49 }
原标题:有趣的checkbox动画切换状态(支付宝转账成功显示)
关键词: