Android中用GifView显示Gif动画

今天工作中,UI给了一个gif图,要求做成网络请求时的加载动画。之前自己记得android中并不能够实线Gif图片,今天去网上搜了一下,发现Android中可以实现Gif图片的显示。下文是通过借助开源‘Gifview‘实现Gif的显示。

效果图:

GifView类,是一位N人写的一个加载Gif动画的类,并且已经将该类做成一个jar类库,供开发者直接加载使用。这个类的使用非常方便,跟普通的UI控件ImageView、Button、TextView等的使用方法都是一样的。


设置GID动画显示的方式:(三种)
先加载后显示:GifImageType.WAIT_FINISH
边加载边显示:GifImageType.SYNC_DECODER
只显示第一帧再显示:GifImageType.COVER

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eeeeee"
    tools:context="iclassmate.net.onlyyou.Main2Activity">
    <com.ant.liao.GifView
        android:id="@+id/gifView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />


    <TextView
        android:id="@+id/tv_loading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/gifView"
        android:text="Loading..."
        android:textSize="14sp" />

</RelativeLayout>
主要代码(非常简单):

public class Main2Activity extends AppCompatActivity {

    private GifView mLoadingImg;
    private TextView mLoadingText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
    }

    private void initView() {
        mLoadingImg = (GifView) findViewById(R.id.gifView);
        mLoadingText=(TextView) findViewById(R.id.tv_loading);

        mLoadingImg.setGifImageType(GifView.GifImageType.WAIT_FINISH);
        mLoadingImg.setGifImage(R.drawable.aa);
        mLoadingText.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/test.ttf"));
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值