Android animation(一.alpha)

本文详细介绍了Android中的动画分类,包括ViewAnimation、TweenAnimation、帧动画FrameAnimation及PropertyAnimation,并重点讲解了补间动画的四种类型:透明度(alpha)、旋转(rotate)、缩放(scale)与移动(translate),同时提供了XML配置示例与代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

动画分类:
View Animation
补间动画  Tween Animation
帧动画    Frame Animation
Property Animation(3.0)


1.补间动画Tween 
alpha(透明度) rotate(旋转) scale(缩放)  translate(移动) 
2.动画监听
AnimationListener
3.帧动画
Frame



alpha:透明度  

实现效果:






alpha属性:

 

android:fromAlpha="" (透明度开始值

android:toAlpha=""透明度结束值

android:duration=""(执行时长 值:毫秒)

android:fillAfter="" (保留动画结束之后的状态 值:true or false)

在文件夹res下新建一个文件夹anim新建一个xml文件如下:


<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.2"
android:duration="1000"
android:fillAfter="true"></alpha>



代码实现:

package com.example.g160628_android_17_animation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private ImageView imageView;
    private Button alpha;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView = (ImageView) findViewById(R.id.main_image);
        alpha = (Button) findViewById(R.id.but_main_alpha);
    }

    public void operation(View view){
        //加载动画
        Animation animation=AnimationUtils.loadAnimation(this,R.anim.iv_alpha);
        //给图片开启动画
        imageView.startAnimation(animation);
    }
}








ven...ivo.hardware.fido@1.0-service E BBinder_init Processname /vendor/bin/hw/vendor.vivo.hardware.fido@1.0-service 2025-06-13 23:56:11.547 6920-6920 vendor.viv....0-service ven...ivo.hardware.fido@1.0-service E BBinder_init hasGetProcessName /vendor/bin/hw/vendor.vivo.hardware.fido@1.0-service 2025-06-13 23:56:11.548 6920-6920 AidlLazySe...eRegistrar ven...ivo.hardware.fido@1.0-service I Registering service vendor.vivo.hardware.fido.IFidoDaemon/default 2025-06-13 23:56:21.325 31338-31338 AndroidRuntime com.example.kucun2 E FATAL EXCEPTION: main Process: com.example.kucun2, PID: 31338 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference at com.example.kucun2.ui.dingdan.OrderDisplayFragment$3.onAnimationEnd(OrderDisplayFragment.java:526) at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:733) at android.animation.Animator$AnimatorCaller$$ExternalSyntheticLambda1.call(D8$$SyntheticClass:0) at android.animation.Animator.callOnList(Animator.java:691) at android.animation.Animator.notifyListeners(Animator.java:624) at android.animation.Animator.notifyEndListeners(Animator.java:654) at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1315) at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1575) at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:496) at android.animation.AnimationHandler.-$$Nest$mdoAnimationFrame(Unknown Source:0) at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:110) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:2457) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:2468) at android.view.Choreographer.doCallbacks(Choreographer.java:1693) at android.view.Choreographer.doFrame(Choreographer.java:1422) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:2284) at android.os.Handler.handleCallback(Handler.java:1014) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loopOnce(Looper.java:250) at android.os.Looper.loop(Looper.java:340) at android.app.ActivityThread.main(ActivityThread.java:9913) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:621) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:957) 1970-01-01 08:00:00.000 0-0 <no-tag> I ---------------------------- PROCESS ENDED (31338) for package com.example.
最新发布
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值