Android控件显示、隐藏时,增加动画效果

android:text=“透明度隐藏”

android:id=“@+id/btn_alpha_hide”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”/>

<ImageView

android:visibility=“invisible”

android:layout_centerHorizontal=“true”

android:layout_marginTop=“20dp”

android:id=“@+id/iv_scale_logo”

android:background=“@mipmap/ic_launcher”

android:layout_width=“100dp”

android:layout_height=“100dp”/>

<LinearLayout

android:layout_marginTop=“10dp”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”>

<Button

android:text=“放大显示”

android:id=“@+id/btn_scale_show”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”/>

<Button

android:text=“缩小隐藏”

android:id=“@+id/btn_scale_hide”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”/>

<ImageView

android:visibility=“invisible”

android:layout_centerHorizontal=“true”

android:layout_marginTop=“20dp”

android:id=“@+id/iv_translate_logo”

android:background=“@mipmap/ic_launcher”

android:layout_width=“100dp”

android:layout_height=“100dp”/>

<LinearLayout

android:layout_marginTop=“10dp”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”>

<Button

android:text=“位移显示(向上)”

android:id=“@+id/btn_translate_show”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”/>

<Button

android:text=“位移隐藏(向下)”

android:id=“@+id/btn_translate_hide”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”/>

MainActivity.java

package com.llw.animationdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.view.animation.AlphaAnimation;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.view.animation.ScaleAnimation;

import android.view.animation.TranslateAnimation;

import android.widget.Button;

import android.widget.ImageView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private ImageView ivLogo, ivAlphaLogo, ivTranslateLogo, ivScaleLogo;

private Button btnShow, btnHide, btnAlphaShow, btnAlphaHide, btnTranslateShow,

btnTranslateHide, btnScaleShow, btnScaleHide;

private AlphaAnimation alphaAniShow, alphaAniHide;

private TranslateAnimation translateAniShow, translateAniHide;

private Animation bigAnimation, smallAnimation;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initView();

}

//初始化控件

private void initView() {

ivLogo = (ImageView) findViewById(R.id.iv_logo);

ivAlphaLogo = (ImageView) findViewById(R.id.iv_alpha_logo);

ivTranslateLogo = (ImageView) findViewById(R.id.iv_translate_logo);

ivScaleLogo = (ImageView) findViewById(R.id.iv_scale_logo);

btnShow = (Button) findViewById(R.id.btn_show);

btnHide = (Button) findViewById(R.id.btn_hide);

btnAlphaShow = (Button) findViewById(R.id.btn_alpha_show);

btnAlphaHide = (Button) findViewById(R.id.btn_alpha_hide);

btnTranslateShow = (Button) findViewById(R.id.btn_translate_show);

btnTranslateHide = (Button) findViewById(R.id.btn_translate_hide);

btnScaleShow = (Button) findViewById(R.id.btn_scale_show);

btnScaleHide = (Button) findViewById(R.id.btn_scale_hide);

btnShow.setOnClickListener(this);

btnHide.setOnClickListener(this);

btnAlphaShow.setOnClickListener(this);

btnAlphaHide.setOnClickListener(this);

btnTranslateShow.setOnClickListener(this);

btnTranslateHide.setOnClickListener(this);

btnScaleShow.setOnClickListener(this);

btnScaleHide.setOnClickListener(this);

alphaAnimation();

scaleAnimation();

translateAnimation();

}

//位移动画

private void translateAnimation() {

//向上位移显示动画 从自身位置的最下端向上滑动了自身的高度

translateAniShow = new TranslateAnimation(

Animation.RELATIVE_TO_SELF,//RELATIVE_TO_SELF表示操作自身

0,//fromXValue表示开始的X轴位置

Animation.RELATIVE_TO_SELF,

0,//fromXValue表示结束的X轴位置

Animation.RELATIVE_TO_SELF,

1,//fromXValue表示开始的Y轴位置

Animation.RELATIVE_TO_SELF,

0);//fromXValue表示结束的Y轴位置

translateAniShow.setRepeatMode(Animation.REVERSE);

translateAniShow.setDuration(1000);

//向下位移隐藏动画 从自身位置的最上端向下滑动了自身的高度

translateAniHide = new TranslateAnimation(

Animation.RELATIVE_TO_SELF,//RELATIVE_TO_SELF表示操作自身

0,//fromXValue表示开始的X轴位置

Animation.RELATIVE_TO_SELF,

0,//fromXValue表示结束的X轴位置

Animation.RELATIVE_TO_SELF,

0,//fromXValue表示开始的Y轴位置

Animation.RELATIVE_TO_SELF,

1);//fromXValue表示结束的Y轴位置

translateAniHide.setRepeatMode(Animation.REVERSE);

translateAniHide.setDuration(1000);

}

//缩放动画

private void scaleAnimation() {

//放大

bigAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.scale_big);

//缩小

smallAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.scale_small);

}

//透明度动画

private void alphaAnimation() {

//显示

alphaAniShow = new AlphaAnimation(0, 1);//百分比透明度,从0%到100%显示

alphaAniShow.setDuration(1000);//一秒

//隐藏

alphaAniHide = new AlphaAnimation(1, 0);

alphaAniHide.setDuration(1000);

}

@Override

public void onClick(View v) {

switch (v.getId()) {

case R.id.btn_show://普通显示

ivLogo.setVisibility(View.VISIBLE);

break;

case R.id.btn_hide://普通隐藏

ivLogo.setVisibility(View.INVISIBLE);

break;

case R.id.btn_alpha_show://透明度显示

ivAlphaLogo.startAnimation(alphaAniShow);

ivAlphaLogo.setVisibility(View.VISIBLE);

break;

case R.id.btn_alpha_hide://透明度隐藏

ivAlphaLogo.startAnimation(alphaAniHide);

//这个地方为什么要做动画的监听呢,因为隐藏和显示不一样,

//必须在动画结束之后再隐藏你的控件,这样才不会显得很突兀

alphaAniHide.setAnimationListener(new Animation.AnimationListener() {

@Override

public void onAnimationStart(Animation animation) {

}

@Override

public void onAnimationEnd(Animation animation) {

ivAlphaLogo.setVisibility(View.INVISIBLE);

}

@Override

public void onAnimationRepeat(Animation animation) {

}

});

break;

case R.id.btn_scale_show://放大显示

ivScaleLogo.startAnimation(bigAnimation);

ivScaleLogo.setVisibility(View.VISIBLE);

break;

case R.id.btn_scale_hide://缩小隐藏

ivScaleLogo.startAnimation(smallAnimation);

smallAnimation.setAnimationListener(new Animation.AnimationListener() {

@Override

public void onAnimationStart(Animation animation) {

}

@Override

public void onAnimationEnd(Animation animation) {

ivScaleLogo.setVisibility(View.INVISIBLE);

}

@Override

public void onAnimationRepeat(Animation animation) {

}

});

break;

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

尾声

对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。 整理的这些架构技术希望对Android开发的朋友们有所参考以及少走弯路,本文的重点是你有没有收获与成长,其余的都不重要,希望读者们能谨记这一点。

最后想要拿高薪实现技术提升薪水得到质的飞跃。最快捷的方式,就是有人可以带着你一起分析,这样学习起来最为高效,所以为了大家能够顺利进阶中高级、架构师,我特地为大家准备了一套高手学习的源码和框架视频等精品Android架构师教程,保证你学了以后保证薪资上升一个台阶。

当你有了学习线路,学习哪些内容,也知道以后的路怎么走了,理论看多了总要实践的。

进阶学习视频

附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题 (含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

架构师,我特地为大家准备了一套高手学习的源码和框架视频等精品Android架构师教程,保证你学了以后保证薪资上升一个台阶。
[外链图片转存中…(img-TTHVRJx0-1712649217130)]
当你有了学习线路,学习哪些内容,也知道以后的路怎么走了,理论看多了总要实践的。

进阶学习视频

[外链图片转存中…(img-1qgERXuO-1712649217131)]

附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题 (含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)

[外链图片转存中…(img-HL6bk48n-1712649217131)]

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

  • 29
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值