您的位置:首页 > 移动开发 > Android开发

android显示gif图片

2015-10-28 11:41 423 查看
1、public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

}

2、<activity

android:name=".MainActivity"

android:label="@string/app_name"

android:screenOrientation="portrait"

android:hardwareAccelerated="false"/>

3、 <com.i.gifview.GifView

android:id="@+id/gv"

android:layout_width="100dp"

android:layout_height="100dp"

android:layout_margin="20dp" />

4、public class GifView extends View {

private long movieStart;

private Movie movie;

// 此处必须重写该构造方法

public GifView(Context context, AttributeSet attributeSet) {

super(context, attributeSet);

movie = Movie.decodeStream(getResources().openRawResource(R.drawable.car));

}

@Override

protected void onDraw(Canvas canvas) {

long curTime = android.os.SystemClock.uptimeMillis();

// 第一次播放

if (movieStart == 0) {

movieStart = curTime;

}

if (movie != null) {

int duraction = movie.duration();

int relTime = (int) ((curTime - movieStart) % duraction);

movie.setTime(relTime);

movie.draw(canvas, 0, 0);

invalidate();

}

super.onDraw(canvas);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: