Android登录页面,未勾选用户协议、隐私政策出现抖动效果

Android登录页面,未勾选用户协议、隐私政策出现抖动效果

其实知识一个简单的补间动画而已

步骤

  1. 如果res目录下没有anim文件,就新建一个文件夹;
  2. 在anim文件夹下创建一个animation.xml动画文件;
  3. 在animation.xml里写上需要的动画属性;
  4. 在代码中使用 AnimationUtils.loadAnimation加载新创建的动画文件;
  5. 在代码中使用View的startAnimation启动动画,完事。

代码

没有写别的效果只是简单的两个控件而已

布局代码

<Button
        android:id="@+id/main_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:text="按钮"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"></Button>


    <TextView
        android:id="@+id/main_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:text="抖动的文字"
        app:layout_constraintBottom_toTopOf="@+id/main_btn"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"></TextView>

其实不用写的 记住空间名称而已

创建动画文件

在anim文件夹下创建一个translate_checkbox_shake.xml动画文件,抖动动画

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300"
    android:fromXDelta="0"
    android:interpolator="@anim/cyc"
    android:toXDelta="30">
 
 
</translate>

再在anim下创建一个插值器,名字叫cyc,这样会有抖动效果

<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    android:cycles="2">
</cycleInterpolator>

注意:android:duration="300"与android:cycles="2"联合表示在300毫秒内将动画执行2次,根据需求来设置就行了。

代码引用:


//创建
  val animation = AnimationUtils.loadAnimation(this,R.anim.translate_checkbox_shake)

        mViewbinding.mainBtn.setOnClickListener {
//使用
            mViewbinding.mainTv.startAnimation(animation)
        }

实现效果 没有 应为没有GIF 工具😭😭
但是肯定可以实现的 本人亲自实现 如果不能
亲自。。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值