zoukankan      html  css  js  c++  java
  • 有趣的checkbox动画切换状态(支付宝转账成功显示)--第三方开源--AnimCheckBox

    这个很有趣的指标通过AnimCheckBox实现,下载地址:https://github.com/lguipeng/AnimCheckBox

    代码:

    activity_main.xml:

     1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     xmlns:app="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.AnimCheckBox
    12         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     <Button
    20         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     @Override
    16     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             @Override
    26             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             @Override
    37             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 }
  • 相关阅读:
    bzoj4537: [Hnoi2016]最小公倍数
    bzoj4331: JSOI2012 越狱老虎桥
    bzoj4558: [JLoi2016]方
    bzoj4209: 西瓜王
    bzoj2653: middle
    bzoj4671: 异或图
    bzoj4771: 七彩树
    shell java应用启动脚本(app.sh)
    Springboot 构建http服务,返回的http行是'HTTP/1.1 200' 无状态码描述 客户端解析错误
    MariaDB(Mysql)-主从搭建
  • 原文地址:https://www.cnblogs.com/zzw1994/p/4999461.html
Copyright © 2011-2022 走看看