位置: 编程技术 - 正文

两个Android开源项目:Android显示GIF动画(安卓开源好处)

编辑:rootadmin

推荐整理分享两个Android开源项目:Android显示GIF动画(安卓开源好处),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:android开源app,安卓开源可以随便用吗,安卓开源好处,android开源app,安卓开源好处,安卓开源部分叫什么,android开源app,android开源软件,内容如对您有帮助,希望把文章链接给更多的朋友!

gifview

主页: 把GifView.jar加入你的项目。

2- 在xml中配置GifView的基本属性,GifView继承自View类,和Button、ImageView一样是一个UI控件。如:

view sourceprint?1.<com.ant.liao.GifView android:id="@&#;id/gif2"2.android:layout_height="wrap_content" android:layout_width="wrap_content"3.android:paddingTop="4px" android:paddingLeft="px" android:enabled="false" />

3- 在代码中配置常用属性:

view sourceprint?.// 从xml中得到GifView的句柄.gf1 = (GifView) findViewById(R.id.gif1);.// 设置Gif图片源.gf1.setGifImage(R.drawable.gif1);.// 添加监听器.gf1.setOnClickListener(this);.// 设置显示的大小,拉伸或者压缩.gf1.setShowDimension(, );.// 设置加载方式:先加载后显示、边加载边显示、只显示第一帧再显示.gf1.setGifImageType(GifImageType.COVER);

GifView的Jar包共有四个类:

GifAction.java:

观察者类,监视GIF是否加载成功

view sourceprint?.package com.ant.liao; .public interface GifAction {./**.*gif解码观察者.* @hide.* @param parseStatus 解码是否成功,成功会为true .* @param frameIndex 当前解码的第几帧,当全部解码成功后,这里为-1 .*/ .public void parseOk(boolean parseStatus,int frameIndex); }

GifFrame.java

里面三个成员:当前图片、延时、下张Frame的链接。

view sourceprint?.package com.ant.liao;.import android.graphics.Bitmap;.public class GifFrame {./**.* 构造函数.* @param im 图片.* @param del 延时.*/ .public GifFrame(Bitmap im, int del) { .image = im; .delay = del; .} .public GifFrame(String name,int del){ .imageName = name; .delay = del; .} ./**图片*/ .public Bitmap image; ./**延时*/ .public int delay; ./**当图片存成文件时的文件名*/.public String imageName = null; ./**下一帧*/ .public GifFrame nextFrame = null;.}

GifDecoder.java

解码线程类

GifView.java

主类,包括常用方法,如GifView构造方法、设置图片源、延迟、绘制等。

android-gif-drawable

android-gif-drawable两个Android开源项目:Android显示GIF动画(安卓开源好处)

Views and Drawable for animated GIFs in Android.

项目地址: GIFLib via JNI is used to render frames. This way should be more efficient thanWebView or Movie classes.Animation starts automatically and run only if View with attached GifDrawable is visible.

Download

Latest release downloads

SetupGradle (Android Studio)

Insert the following dependency to build.gradle file of your project.

view sourceprint?1.dependencies {2.compile 'pl.droidsonroids.gif:android-gif-drawable:1.0.&#;'3.}

Note that Maven central repository should be defined eg. in top-level build.gradle like this:

view sourceprint?.buildscript {.repositories {.mavenCentral().}.}.allprojects {.repositories {.mavenCentral().}.}Maven dependency

SDK with API level is needed. If you don't have it in your local repository, downloadmaven-android-sdk-deployer and install SDK level :mvn install -P 4.4 (from maven-android-sdk-deployer directory). Then add dependency inpom.xml of your project:

view sourceprint?1.<dependency>2.<groupId>pl.droidsonroids.gif</groupId>3.<artifactId>android-gif-drawable</artifactId>4.<version>insert latest version here</version>5.<type>aar</type>6.</dependency>RequirementsAndroid 1.6&#; (API level 4&#;)Building from sourceAndroid NDK needed to compile native sourcesUsageFrom XML

The simplest way is to use GifImageView (or GifImageButton) like a normalImageView:

view sourceprint?1.<pl.droidsonroids.gif.GifImageView2.android:layout_width="match_parent"3.android:layout_height="match_parent"4.android:src="@drawable/src_anim"5.android:background="@drawable/bg_anim"6./>

If drawables declared by android:src and/or android:background are GIF files then they will be automatically recognized asGifDrawables and animated. If given drawable is not a GIF then mentioned Views work like plainImageView and ImageButton.

GifTextView allows you to use GIFs as compound drawables and background.

view sourceprint?1.<pl.droidsonroids.gif.GifTextView2.android:layout_width="match_parent"3.android:layout_height="match_parent"4.android:drawableTop="@drawable/left_anim"5.android:drawableStart="@drawable/left_anim"6.android:background="@drawable/bg_anim"7./>From Java code

GifImageView, GifImageButton and GifTextView have also hooks for setters implemented. So animated GIFs can be set by callingsetImageResource(int resId) and setBackgroundResource(int resId)

GifDrawable can be constructed directly from various sources:

view sourceprint?.//asset file.GifDrawable gifFromAssets = new GifDrawable( getAssets(), "anim.gif" );. .//resource (drawable or raw).GifDrawable gifFromResource = new GifDrawable( getResources(), R.drawable.anim );. .//byte array.byte[] rawGifBytes = ....GifDrawable gifFromBytes = new GifDrawable( rawGifBytes );. .//FileDescriptor.FileDescriptor fd = new RandomAccessFile( "/path/anim.gif", "r" ).getFD();.GifDrawable gifFromFd = new GifDrawable( fd );. .//file path.GifDrawable gifFromPath = new GifDrawable( "/path/anim.gif" );. .//file.File gifFile = new File(getFilesDir(),"anim.gif");.GifDrawable gifFromFile = new GifDrawable(gifFile);. .//AssetFileDescriptor.AssetFileDescriptor afd = getAssets().openFd( "anim.gif" );.GifDrawable gifFromAfd = new GifDrawable( afd );. .//InputStream (it must support marking).InputStream sourceIs = ....BufferedInputStream bis = new BufferedInputStream( sourceIs, GIF_LENGTH );.GifDrawable gifFromStream = new GifDrawable( bis );. .//direct ByteBuffer.ByteBuffer rawGifBytes = ....GifDrawable gifFromBytes = new GifDrawable( rawGifBytes );

InputStreams are closed automatically in finalizer if GifDrawable is no longer needed so you don't need to explicitly close them. Callingrecycle() will also close underlaying input source.

Note that all input sources need to have ability to rewind to the begining. It is required to correctly play animated GIFs (where animation is repeatable) since subsequent frames are decoded on demand from source.

Animation control

GifDrawable implements an Animatable and MediaPlayerControl so you can use its methods and more:

stop() - stops the animation, can be called from any threadstart() - starts the animation, can be called from any threadisRunning() - returns whether animation is currently running or notreset() - rewinds the animation, does not restart stopped onesetSpeed(float factor) - sets new animation speed factor, eg. passing 2.0f will double the animation speedseekTo(int position) - seeks animation (within current loop) to givenposition (in milliseconds) Only seeking forward is supportedgetDuration() - returns duration of one loop of the animationgetCurrentPosition() - returns elapsed time from the beginning of a current loop of animationUsingMediaPlayerControl

Standard controls for a MediaPlayer (like in VideoView) can be used to control GIF animation and show its current progress.

Just set GifDrawable as MediaPlayer on your MediaController like this:

view sourceprint?.@Override.protected void onCreate ( Bundle savedInstanceState ).{.super.onCreate( savedInstanceState );.GifImageButton gib = new GifImageButton( this );.setContentView( gib );.gib.setImageResource( R.drawable.sample );.final MediaController mc = new MediaController( this );.mc.setMediaPlayer( ( GifDrawable ) gib.getDrawable() );.mc.setAnchorView( gib );.gib.setOnClickListener( new OnClickListener().{.@Override.public void onClick ( View v ).{.mc.show();.}.} );.}Retrieving GIF metadatagetLoopCount() - returns a loop count as defined in NETSCAPE 2.0 extensiongetNumberOfFrames() - returns number of frames (at least 1)getComment() - returns comment text (null if GIF has no comment)getFrameByteCount() - returns minimum number of bytes that can be used to store pixels of the single framegetAllocationByteCount() - returns size (in bytes) of the allocated memory used to store pixels of given GifDrawablegetInputSourceByteCount() - returns length (in bytes) of the backing input datatoString() - returns human readable information about image size and number of frames (intended for debugging purpose)Advancedrecycle() - provided to speed up freeing memory (like in android.graphics.Bitmap).getError() - returns last error detailsReferences

This library uses code from GIFLIB 5.0.5 and SKIA.

License

MIT LicenseSee LICENSE file.

PS:

GifView:已知bug: 如果图档过大,会出现OOM

if the gif image is too large,maybe OOM.

为了解决图档太大时的OOM,我想把gif解析时的图片先存入到文件中,在显示时直接从文件中读入,但这样的话,显示的效果不好。

而android-gif-drawable并没有此问题,底层解码使用C实现,极大的提高了解码效率,同时很大程度上避免了OOM现象出现。

最新推荐Bluemix 移动开发学习路线图 移动和云开发是目前最热门的技术主题,如何将两者结合,实现云平台上的移动应用迅速开发和部署是目前企业和开发人员经常探讨的问题。Bluemix是IBM

【Android】Eclipse自动编译NDK/JNI的三种方法 一、Eclipse关联cygwin1.工程-右击选择Properties-选择Builders,在Builders中选择New创建一个Program2.参数配置二、Eclipse关联ndk-build(自建Builder方法)1.Project-Propert

Android学习之开源项目PullToRefresh的使用 首先下载Android-PullToRefresh-master下载地址

标签: 安卓开源好处

本文链接地址:https://www.jiuchutong.com/biancheng/374506.html 转载请保留说明!

上一篇:直接利用Android手机破解微信加密数据库EnMicroMsg.db(直接利用外资)

下一篇:最新推荐Bluemix 移动开发学习路线图(最新推荐美剧)

  • 增值税专用发票有效期是多长时间
  • 小规模免缴增值税吗
  • 自产用于捐赠的会计处理
  • 营业执照注销要收费用吗
  • 利润表的未分配利润是哪个
  • 建筑企业一般纳税人简易计税办法
  • 企业职工薪酬的个人所得税纳税筹划研究
  • 多计提的工资怎么处理?
  • 公司支付宝账户怎么登录
  • 减免税款记账营业外收入什么科目?
  • 补充医疗保险 个人账户可以报销吗
  • 机动车发票抵扣联有什么用
  • 企业拿到产权证后是否还需要缴纳土地使用税呢?
  • 上海中级会计报名入口
  • 审计报告报备流程
  • 建筑公司分包
  • 企业所得税年报申报时间
  • 苹果手机铃声删除在哪里
  • cpqeadm.exe是什么进程 可以关闭吗 cpqeadm进程查询
  • 完美解决索尼电视arc无声音
  • PHP:mcrypt_get_block_size()的用法_Mcrypt函数
  • 政府闲置土地
  • wamp怎么运行php文件
  • win10系统的安装
  • 编译安装php8
  • php多进程处理大数据
  • 保障金是低保吗
  • 公司卖地如何交税
  • 企业支付宝提现到对公账户手续费
  • PhoneGap was accuriqed by adobe
  • mysql5.7.33压缩包安装教程
  • mongodb数据查询
  • 收到退回的企业所得税分录
  • 履约保证金能否委托支付
  • 每个公司都要交五险一金吗
  • 事务所的账务处理
  • 总账和明细账期间相同吗
  • 限额领料单属于什么凭证多选题
  • 一次性发放年终奖金怎么扣除个人所得税144000有何意义
  • 个人利息收入怎么计算个税
  • mysql的lsn
  • sql删除表中的某一行
  • 股东的投资款怎么收回
  • 个人开咨询费 有哪些税
  • 摊余成本通俗易懂
  • 股东权益合计是所有者权益总和么
  • 税法中特许权费包括哪些
  • 隔月发票退回是怎么回事
  • 劳务派遣和劳务承揽的区别
  • 如何解决私账流失问题
  • 取得的政府补助收入计入
  • 调试机器要注意事项
  • 公司内部核算调研报告
  • 废旧物资收购发票政策2018
  • 预包装食品是否可以称重销售吗
  • 个人经纪代理服务
  • 小规模需要进项税额吗
  • 没有开票的收入要交增值税吗
  • 会计怎么核对出纳的日记账
  • 年化利率是什么意思
  • 单独设置停工损失科目
  • sql数据库还原方法
  • windows10秋季创意者更新
  • ie8-ie11
  • windows隐藏文件夹开启
  • mmc无法创建管理单元怎么办win11
  • 自动保存怎么恢复
  • 电脑windows7无法验证此文件
  • unity输入中文
  • chromexcel
  • visual studio 10 cocos2dx项目移植到eclipse的android项目(配置请参照上一篇文章开发环境搭建)
  • jqueryanimate动画
  • jquery移动端ui框架
  • 省市区json
  • 记住密码自动登录怎么取消
  • 搞农业种植
  • 麻将 空白
  • 苏州社保代缴机构查询
  • 庐山坐缆车上去后还要买门票吗?
  • 人均可支配收入是到手工资吗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设