最早期的动画制作方式,使用不同的图片连续拨放
先将图片放入专案,并在drawable下建立一个XML档,定义图片集合,并把图片依序放置於集合中。
<?xml version ="1.0" encoding ="utf-8"?><!-- Learn More about how to use App Actions: https://developer.android.com/guide/actions/index.html -->
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/food1"
android:duration="200"/>
<item
android:drawable="@drawable/food2"
android:duration="200"/>
<item
android:drawable="@drawable/food3"
android:duration="200"/>
</animation-list>
启用动画
package com.example.lab10
import android.graphics.drawable.AnimationDrawable
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//教科书上没有这句,但我编译器过不了我还是自己加了XD
val img_loading = findViewById<ImageView>(R.id.img_loading)
//将动画的drawable指定为ImageView的背景资源
img_loading.setBackgroundResource(R.drawable.frame_animation)
findViewById<Button>(R.id.btn_start).setOnClickListener{
//将图片背景转为AnimationDrawable类别并执行
val animation = img_loading.background as AnimationDrawable
animation.start()
}
findViewById<Button>(R.id.btn_stop).setOnClickListener{
//将图片背景转为AnimationDrawable类别并停止
val animation = img_loading.background as AnimationDrawable
animation.stop()
}
}
}
这个动画实作踩了一个坑是,我先建立了XML档,但不知道是不是建立方式错误,他一直从drawable跑到xml资料夹去,搞到後来我抓狂,直接从MainActivity中对着frame_animation按Alt+Enter,让IDE帮我生一个XML出来,才成功运行。
接续昨天 response headers 的部分 一样是看 Julia Evans 大大的可爱的图...
本文章同时发布於: Medium iT 邦帮忙 大家好,这几天较有时间,终於可以好好的思考文章 XD...
程序码说明 一般执行的程序大多会有以下架构: int main(){ 程序码 } 程序在执行的时候,...
Q1. Graph 是什麽 Graph 定义:一个 graph 由 数个点( vertex )与数个...
hi~经过三天有关solidity语法讲解的过程,那今天就来做一个小实作!我们来写一个有关加法与减...