同步操作将从 WAY/WayGif 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
##WayGif
Android端通过jni解析显示gif图片,更高效,更速度。 原项目来自Github: android-gif-drawable
##简单使用
###在layout布局XML文件中:
跟使用普通的 ImageView
一样使用 GifImageView
(或者 GifImageButton
):
<com.way.gif.GifImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/src_anim"
android:background="@drawable/bg_anim"
/>
如果 android:src
或者 android:background
使用的是GIF文件,运行程序后,将会自动播放。
GifTextView
允许使用gif文件作为背景.
<com.way.gif.GifTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawableTop="@drawable/left_anim"
android:drawableStart="@drawable/left_anim"
android:background="@drawable/bg_anim"
/>
###在Java代码中:
GifImageView
, GifImageButton
and GifTextView
可以直接调用 setImageResource(int resId)
and setBackgroundResource(int resId)
设置GIF文件图片。
GifDrawable
也能在代码中直接实例化:
//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
会在 GifDrawable
不再使用时自动关闭,因此你不用特意去关闭它,当然也可以调用 recycle()
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 given position
(in milliseconds) Only seeking forward is supported
getDuration()
- returns duration of one loop of the animationgetCurrentPosition()
- returns elapsed time from the beginning of a current loop of animation#####Using MediaPlayerControl 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:
@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 metadata
getLoopCount()
- 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)####Advanced
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。