当前位置:网站首页>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
边栏推荐
- 基础软件与开发语言开源论坛| ChinaOSC
- 要想成为黑客,离不开这十大基础知识
- Word另存为PDF后无导航栏解决办法
- 标准C语言学习总结11
- 622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
- Unity获取canvas 下ui 在屏幕中的实际坐标
- X86 function call model analysis
- Jingdong cloud released a new generation of distributed database StarDB 5.0
- 普通用户如何利用小红书赚钱呢?小红书的流量是真的吗?
- OneNote 教程,如何在 OneNote 中设置页面格式?
猜你喜欢
随机推荐
Shell programming loop statement
X86 function call model analysis
力扣刷题之移动零
2022年最新的Android面试大厂必考174题(附带详细答案)
基于移动GIS的环保生态管理系统
ECCV2022 | 用于视频问题回答的视频图Transformer
docker mysql 容器中执行mysql脚本文件并解决乱码
Handler 源码解析
Protobuf Grpc使用异常 类型有未导出的方法,并且是在不同的软件包中定义
虚拟机vmware设置nat模式上网
Interview Blitz: What Are Sticky Packs and Half Packs?How to deal with it?
FreeRTOS Intermediate
Postgresql源码(64)查询执行——子模块Executor(2)执行前的数据结构和执行过程
Radondb mysql installation problems
DeepMCP网络详解
InnoDB 中不同SQL语句设置的锁
开发即时通讯到底需要什么样的技术,需要多久的时间
微信小程序分享功能
云图说丨初识华为云微服务引擎CSE
flex布局









