当前位置:网站首页>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
边栏推荐
- 从文本匹配到语义相关——新闻相似度计算的一般思路
- 力扣刷题之合并两个有序数组
- 【Azure 事件中心】使用Azure AD认证方式创建Event Hub Consume Client + 自定义Event Position
- Handler 源码解析
- 手把手教你定位线上MySQL慢查询问题,包教包会
- 标准C语言学习总结11
- Teach you to locate online MySQL slow query problem hand by hand, package teaching package meeting
- NNLM、RNNLM等语言模型 实现 下一单词预测(next-word prediction)
- 力扣刷题之有效的正方形(每日一题7/29)
- 国产虚拟化云宏CNware WinStack安装体验-5 开启集群HA
猜你喜欢
Solution for no navigation bar after Word is saved as PDF
基于DMS的数仓智能运维服务,知多少?
友宏医疗与Actxa签署Pre-M Diabetes TM 战略合作协议
「游戏建模干货」建模大师几步操作,学习经典,赶紧脑补一下吧
go语言实现导出string字符串到文件中
ctfshow php features
不要再用if-else
Kettle 读取 Excel 数据输出到 Oracle 详解
Jingdong cloud released a new generation of distributed database StarDB 5.0
ECCV 2022 Oral | 满分论文!视频实例分割新SOTA: IDOL
随机推荐
Power button brush the topic of merging two orderly array
Introduction to Cosine Distance
高效目标检测:动态候选较大程度提升检测精度(附论文下载)
云图说丨初识华为云微服务引擎CSE
盲僧发现了华点——教你如何使用API接口获取数据
ctfshow php特性
告诉你0基础怎么学好游戏建模?
【C语言学习笔记(五)】while循环与for循环
【微信小程序】NFC 标签打开小程序
X86 function call model analysis
梅科尔工作室-14天华为培训七
ScrollView嵌套RV,滑动有阻力不顺滑怎么办?
开源教育论坛| ChinaOSC
ctfshow php features
盘点在线帮助中心对企业能够起到的作用
虚拟机vmware设置nat模式上网
力扣刷题之合并两个有序数组
1161 最大层内元素和——Leetcode天天刷【BFS】(2022.7.31)
安装anaconda并创建虚拟环境
relocation R_X86_64_PC32 against,/usr/bin/ld: final link failed: Bad value