Android Gif動態圖片庫

Gif動態圖片庫: 播放Gif圖片, Gif動畫監聽。

首先添加GifView庫和ImageLoader庫的gradle依賴:

implementation 'com.github.Cutta:GifView:1.1'

xml文件使用:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context="com.example.dpl.gifviewdemo.MainActivity">
 
    <com.cunoraz.gifview.library.GifView
        android:id="@+id/gifView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
 
</LinearLayout>

使用

 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
 
import com.cunoraz.gifview.library.GifView;
 
/*
加載本地GIF圖片,使用gifView
 */
public class MainActivity extends AppCompatActivity {
    private GifView gifView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gifView= (GifView) findViewById(R.id.gifView);
        //設置圖片源
        gifView.setGifResource(R.drawable.wanshengjie);//本地圖片
        //位置設置
        gifView.setX(150);
        gifView.setY(300);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章