前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >【鼠】安卓学习杂记(二十八)——Android动画之帧动画

【鼠】安卓学习杂记(二十八)——Android动画之帧动画

作者头像
訾博ZiBo
发布2025-01-06 13:54:18
发布2025-01-06 13:54:18
9000
代码可运行
举报
文章被收录于专栏:全栈开发工程师
运行总次数:0
代码可运行
一、效果图

二、布局xml
代码语言:javascript
代码运行次数:0
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/iv1"
        android:layout_width="300dp"
        android:layout_height="300dp"/>

</LinearLayout>
三、动画xml
代码语言:javascript
代码运行次数:0
复制
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/a1" android:duration="100" />
    <item android:drawable="@drawable/a2" android:duration="100" />
    <item android:drawable="@drawable/a3" android:duration="100" />
    <item android:drawable="@drawable/a4" android:duration="100" />
    <item android:drawable="@drawable/a5" android:duration="100" />
    <item android:drawable="@drawable/a6" android:duration="100" />
    <item android:drawable="@drawable/a7" android:duration="100" />
    <item android:drawable="@drawable/a8" android:duration="100" />
    <item android:drawable="@drawable/a9" android:duration="100" />
    <item android:drawable="@drawable/a10" android:duration="100" />
</animation-list>
四、图片
五、Java代码
代码语言:javascript
代码运行次数:0
复制
package com.example.administrator.app_animation;

import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    ImageView iv1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv1 = findViewById(R.id.iv1);
        //把帧动画的资源文件指定为iv的背景
        iv1.setBackgroundResource(R.drawable.my_animation);
        //获取iv的背景
        AnimationDrawable ad = (AnimationDrawable) iv1.getBackground();
        ad.start();
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-01-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、效果图
  • 二、布局xml
  • 三、动画xml
  • 四、图片
  • 五、Java代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档