当前位置:网站首页>glide set gif start stop
glide set gif start stop
2022-08-03 19:34:00 【勘察加熊人】
一张gif图片,控制播放和暂停,用了一个取巧的办法实现的,使用glide和selector.xml文件实现
step1: D:\workspace\MyApplication26\app\build.gradle
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
step2:
package com.example.ali.myapplication
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import com.bumptech.glide.Glide
class MainActivity : AppCompatActivity() {
private lateinit var btn_start: Button
private lateinit var btn_stop: Button
private lateinit var iv_rc_home: ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btn_stop = findViewById(R.id.btn_stop)
btn_start = findViewById(R.id.btn_start)
iv_rc_home = findViewById(R.id.iv_rc_home)
btn_start.setOnClickListener {
Glide.with(this).load(R.drawable.fan_five.gif).into(iv_rc_home);
}
btn_stop.setOnClickListener {
Glide.with(this).load(R.drawable.home_select_fan.xml).into(iv_rc_home);
}
}
}
step3: home_select_fan.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/fan_five.gif" />
</selector>
step4:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" />
<Button android:id="@+id/btn_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始播放" />
<Button android:id="@+id/btn_stop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="停止" />
<ImageView android:id="@+id/iv_rc_home" android:layout_width="335dp" android:layout_height="252dp" android:src="@mipmap/ic_launcher" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
end
边栏推荐
- JS 内置构造函数 扩展 prototype 继承 借用构造函数 组合式 原型式creat 寄生式 寄生组合式 call apply instanceof
- ADS 2023 Download Link
- OneNote 教程,如何在 OneNote 中设置页面格式?
- pg_memory_barrier_impl in Postgresql and C's volatile
- YAML中多行字符串的配置方法:|+、 |、 |-、 >+、 >、 >-的区别
- 面试突击:什么是粘包和半包?怎么解决?
- 分享即时通讯开发之WebSocket:概念、原理、易错常识、动手实践
- 数据驱动的软件智能化开发| ChinaOSC
- 2022 CCF中国开源大会会议通知(第三轮)
- Postgresql-xl global snapshot and GTM code walking (branch line)
猜你喜欢

怎么将自己新文章自动推送给自己的粉丝(巨简单,学不会来打我)

盲僧发现了华点——教你如何使用API接口获取数据

JumpServer开源堡垒机完成龙芯架构兼容性认证

CC2530_ZigBee+华为云IOT:设计一套属于自己的冷链采集系统

go语言实现导出string字符串到文件中
手把手教你定位线上MySQL慢查询问题,包教包会

Reveal how the five operational management level of hundreds of millions of easily flow system

阿里巴巴政委体系-第八章、阿里政委工作方法论

YAML中多行字符串的配置方法:|+、 |、 |-、 >+、 >、 >-的区别

MySQL基础
随机推荐
Execute the mysql script file in the docker mysql container and solve the garbled characters
JS 内置构造函数 扩展 prototype 继承 借用构造函数 组合式 原型式creat 寄生式 寄生组合式 call apply instanceof
MySQL基础
线上一次JVM FullGC搞得整晚都没睡,彻底崩溃
【leetcode】剑指 Offer II 009. 乘积小于 K 的子数组(滑动窗口、双指针)
net-snmp私有mib动态加载到snmpd
余弦距离介绍
MySQL读写分离的三种实现方案
【C语言学习笔记(七)】C语言重定向输入与输出
docker mysql 容器中执行mysql脚本文件并解决乱码
ADS 2023 下载链接
高效目标检测:动态候选较大程度提升检测精度(附论文下载)
622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
从文本匹配到语义相关——新闻相似度计算的一般思路
「游戏建模干货」建模大师几步操作,学习经典,赶紧脑补一下吧
数据驱动的软件智能化开发| ChinaOSC
系统太多,多账号互通如何实现?
relocation R_X86_64_PC32 against,/usr/bin/ld: final link failed: Bad value
【leetcode】剑指 Offer II 008. 和大于等于 target 的最短子数组(滑动窗口,双指针)
ctfshow php features