请问我有gifview的问题。
我认为我需要的是:
我需要把我的gifimage放到RAM内存中。
package com.paradox02.dell.dormation01;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class GifView extends View{
// int pom=0;
private final static String STORETEXT6="index2.txt";
public static int indexG2;
int[] images = {
R.drawable.troj1,R.drawable.troj2,R.drawable.troj3,R.drawable.troj4,R.drawable.troj5, //0-4
R.drawable.koc1,R.drawable.koc5,R.drawable.koc3,R.drawable.koc4,R.drawable.koc2,//5-9
R.drawable.kruh1,R.drawable.kruh2,R.drawable.kruh3, ///10-12
R.drawable.tutorial1,
R.drawable.tutorial2,
R.drawable.tutorial3,
R.drawable.nic,
};
private InputStream gifInputStream;
private Movie gifMovie;
private int movieWidth, movieHeight;
private long movieDuration;
private long movieStart;
private Integer index2;
private Context co;
public GifView(Context context) {
super(context);
co = context;
init(context);
}
public GifView(Context context, AttributeSet attrs) {
super(context, attrs);
co = context;
init(context);
}
public GifView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
co = context;
init(context);
}
private void init(Context context) {
setFocusable(true);
//read();
gifInputStream = context.getResources().openRawResource(images[indexG2]);
gifMovie = Movie.decodeStream(gifInputStream);
movieWidth = gifMovie.width();
movieHeight = gifMovie.height();
movieDuration = gifMovie.duration();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(movieWidth, movieHeight);
}
@Override
protected void onDraw(Canvas canvas) {
long now = SystemClock.uptimeMillis();
if(movieStart == 0) {
movieStart = now;
}
read();
new Thread(new Runnable() {
public void run() {
gifMovie = Movie.decodeStream(gifInputStream);
movieWidth = gifMovie.width();
movieHeight = gifMovie.height();
movieDuration = gifMovie.duration();
}
}).start();
}
if(gifMovie != null) {
int dur = gifMovie.duration();
if(dur == 0) {
dur = 1000;
}
int relTime = (int)((now - movieStart) % dur);
gifMovie.setTime(relTime);
gifMovie.draw(canvas, 0, 0);
invalidate();
}
}
public void read() {
try {
InputStream in3 = getContext().openFileInput(STORETEXT6);
if (in3 != null) {
InputStreamReader tmp = new InputStreamReader(in3);
BufferedReader reader = new BufferedReader(tmp);
String str;
StringBuilder buf3 = new StringBuilder();
while ((str = reader.readLine()) != null) {
buf3.append(str);
}
in3.close();
indexG2=Integer.valueOf(buf3.toString().trim());
}
} catch (java.io.FileNotFoundException e) {
// that's OK, we probably haven't created it yet
} catch (Throwable t) {
}
}
}
我尝试将一些代码放入Thread(可运行)加速。
我在主代码上调用此类:
gifView2 =(GifView2)findViewById(R.id.gif_view2);
<com.paradox02.dell.dormation01.GifView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gif_view"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerInside"/>
应用已在Google Play上公开
当我玩app时,有时所有进程都会崩溃并在显示屏上写入&#34;加载启动器&#34;
请帮帮我。
感谢任何建议。
如果您需要更多代码,请写=&gt;我会说。
对不起我的英语