Android实现登录注册动画切换功能
龙旋
共 6526字,需浏览 14分钟
· 2021-08-13
public class LoginMainActivity extends AppCompatActivity {
//判断是登录还是注册
private boolean isLogin = true;
private Fragment[] mFragments;
private Fragment mLastFragment;
private RelativeLayout mRl;
private Button mBtn;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_main_layout);
findView();
}
//查询控件
private void findView() {
mRl = findViewById(R.id.id_rl);
mBtn = findViewById(R.id.id_btn);
mFragments = new Fragment[]{new LoginInFragment(), new SignUpFragment()};
//默认登录动画
switchLogin();
//点击切换登录或注册
mBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isLogin();
}
});
}
//"去注册"按钮从左边平移出来
private void btnTranslateLeft(){
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mBtn, "translationX",-Px2DpUtil.dp2px(this,100) , Px2DpUtil.dp2px(this,20));
objectAnimator.setDuration(getResources().getInteger(R.integer.anim_short));
objectAnimator.setInterpolator(new AccelerateInterpolator());
objectAnimator.start();
}
//“去登录”按钮从右边平移出来
private void btnTranslateRight(){
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mBtn, "translationX", ScreenUtil.getScreenWidth(), ScreenUtil.getScreenWidth()-Px2DpUtil.dp2px(this,120));
objectAnimator.setDuration(getResources().getInteger(R.integer.anim_short));
objectAnimator.setInterpolator(new AccelerateInterpolator());
objectAnimator.start();
}
//背景色渐变
private void animColor(int colorTo) {
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), R.color.white, colorTo);
colorAnimation.setDuration(getResources().getInteger(R.integer.anim_short));
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
int color = (int) animator.getAnimatedValue();
mRl.setBackgroundColor(color);
}
});
colorAnimation.start();
}
//执行登录页面动画
private void switchLogin() {
isLogin = true;
switchFragment(mFragments[0], R.anim.rotate_fg_enter_left, R.anim.rotate_fg_exit_left);
animColor(ContextCompat.getColor(this, R.color.c_499AF7));
btnTranslateLeft();
mBtn.setText("去注册");
}
//执行注册页面动画
private void switchSignUp(){
isLogin = false;
switchFragment(mFragments[1], R.anim.rotate_fg_enter_right, R.anim.rotate_fg_exit_right);
animColor(ContextCompat.getColor(this, R.color.c_3ec88e));
btnTranslateRight();
mBtn.setText("去登录");
}
private void isLogin() {
if (isLogin) {
switchSignUp();
} else {
switchLogin();
}
}
/**
* Fragment切换
*
* @param fragment
*/
public void switchFragment(Fragment fragment, int enter, int exit) {
try {
if (fragment == null) {
fragment = mFragments[0];
}
if (fragment.equals(mLastFragment)) {
return;
}
FragmentManager mFragmentManager = getSupportFragmentManager();
FragmentTransaction mTransaction = mFragmentManager.beginTransaction();
//执行fragment切换动画
mTransaction.setCustomAnimations(enter, exit);
if (mLastFragment != null) {
mTransaction.hide(mLastFragment);
}
if (!fragment.isAdded()) {
mTransaction.add(R.id.id_fl_login_in, fragment);
} else {
mTransaction.show(fragment);
}
mTransaction.commitAllowingStateLoss();
} catch (Exception e) {
e.printStackTrace();
} finally {
mLastFragment = fragment;
}
}
}
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_rl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/id_fl_login_in"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Button
android:id="@+id/id_btn"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp"
android:background="@drawable/shape_btn_login_in"
android:text="去注册"
android:textColor="#95ffffff"
android:textSize="20sp"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="@integer/anim_short"
android:toDegrees="0"
android:fromDegrees="180"
android:interpolator="@android:anim/bounce_interpolator"
/>
</set>
rotate_fg_exit_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="@integer/anim_short"
android:fromDegrees="0"
android:toDegrees="-180"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/bounce_interpolator"
android:duration="@integer/anim_short"
android:toDegrees="0"
android:fromDegrees="-180"
/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="@integer/anim_short"
android:fromDegrees="0"
android:toDegrees="180"/>
</set>
评论
15种时间序列预测方法总结(包含多种方法代码实现)
向AI转型的程序员都关注了这个号👇👇👇在这篇文章中,我们将深入探讨时间序列预测的基本概念和方法。我们将首先介绍单元预测和多元预测的概念,然后详细介绍各种深度学习和传统机器学习方法如何应用于时间序列预测,包括循环神经网络(RNN)、一维卷积神经网络(1D-CNN)、Transformer、自回归模型(
机器学习AI算法工程
0
Go 1.22 的新增功能系列之二:reflect.TypeFor
Go 1.22 的第一个候选版本已经发布,这意味着最终版本即将发布,现在是我在博客中介绍我在这个周期中所做工作的时候了。像往常一样,我的贡献很小,但它们是我的,所以我将从幕后的角度来谈谈它们。首先是reflect.TypeFor。这是整个函数:// TypeFor returns the [Type
GoCN
0
SpringBoot 实现图片防盗链功能
程序员的成长之路互联网/程序员/技术/资料共享 关注阅读本文大概需要 4 分钟。来自:blog.csdn.net/weixin_46157208/article/details/138051737前言出于安全考虑,我们需要后端返回的图片只允许在某个网站内展示,不想被爬虫拿到图片地
程序员的成长之路
0
一站式解决方案:基于 Arthas 实现服务发现和权限控制
来源:juejin.cn/post/7281849496983994383👉 欢迎加入小哈的星球 ,你将获得: 专属的项目实战 / Java 学习路线 / 一对一提问 / 学习打卡 / 赠书福利全栈前后端分离博客项目 2.0 版本完结啦, 演示链接
小哈学Java
0
用 Shader 实现旗帜飘扬动画效果
我觉得对于刚入门 3D 编程的朋友来说,如果能够完成代码创建模型数据->创建材质->编写Shader动画这一系列,想必会有满满的成就感。今天就用 Cocos Creator 的 utils.MeshUtils.createMesh 接口,带大家感受一下这个流程。这个流程不仅可以用于新手学
COCOS
2
Go 1.22 的新增功能系列之一:cmp.Or
截至撰写本文时,Go 1.22 已经发布几个月了。早就该结束我为 1.22 所做的工作的系列了。抱歉耽搁了这么久,我最近忙于生活事务。如果您错过了我关于reflect.TypeFor(https://blog.carlana.net/post/2024/golang-reflect-type-for
GoCN
1
21.3K star!推荐一款可视化自动化测试/爬虫/数据采集神器!功能免费且强大!
【温馨提示】由于公众号更改了推送规则,不再按照时间顺序排列,如果不想错过测试开发技术精心准备的的干货文章,请将测试开发技术设为“星标☆”,看完文章在文尾处点亮“在看”!大家好,我是狂师!在大数据时代,信息的获取与分析变得尤为重要。对于开发者、数据分析师乃至非技术人员来说,能够高效地采集网络数据并进行
测试开发技术
4
知乎高问:程序员有必要知道为什么做某个功能吗?
将Python客栈设为“星标⭐”第一时间收到最新资讯前言知乎上有一个提问:程序员有必要知道为什么做某个功能吗?↓↓↓今天,我们就这个话题一起来做个讨论。不知道程序员的你,在接到产品经理提的一个需求后,是习惯马上动手开始撸代码呢?还是会先暂停一下,认真思考一会如下一些问题,比如这个需求产生的背景是什么
Python客栈
0