问题描述
我想显示GIF图片我已经使用这个code
i am trying to display gif image i have used this code
MainActivity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MYGIFView(this));
}
}
和 MYGIFView 类:
public class MYGIFView extends View {
Movie movie,movie1;
InputStream is=null,is1=null;
long moviestart;
public MYGIFView(Context context) {
super(context);
is=context.getResources().openRawResource(R.drawable.piggy);
movie=Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
super.onDraw(canvas);
long now=android.os.SystemClock.uptimeMillis();
System.out.println("now="+now);
if (moviestart == 0) { // first time
moviestart = now;
}
System.out.println("\tmoviestart="+moviestart);
int relTime = (int)((now - moviestart) % movie.duration()) ;
System.out.println("time="+relTime+"\treltime="+movie.duration());
movie.setTime(relTime);
movie.draw(canvas,this.getWidth()/2-20,this.getHeight()/2-40);
this.invalidate();
}
}
它显示在仿真器和gif worrks drawale文件夹中的GIF图像,但是当我在真实的设备运行这个就说明什么 ...请告诉我这里的问题?
It shows gif image from drawale folder in emulator and gif worrks but when i run this in real device it shows nothing... Whats the problem here??
推荐答案
电影对象是作为硬件加速在这些设备上启用不能正常上的设备上面(4.x的)工作。因此,通过硬件加速禁用,可以使图像上都模拟器和真实的设备正常工作。
Movie Object is not work properly on Device above(4.x) as hardware acceleration is enabled in these devices. So by making hardware acceleration disabled, you can make images work on both emulator and on real device.
-
您可以通过添加禁用硬件加速
You can disabled hardware acceleration by adding
安卓hardwareAccelerated =FALSE
android:hardwareAccelerated="false"
在您的清单文件因德尔活动标签
in your manifest file inder activity tag
<activity
android:name=".MainActivity"
android:hardwareAccelerated="false"
android:label="@string/app_name" >
</activity>
2.you也可以禁用硬件acceration编程
2.you can also disabled hardware acceration programatically
例如:MYGIFView是你要去哪里,以显示你的GIF图片自定义视图
for example: MYGIFView is your custom view where you are going to show your GIF images
MYGIFView mMYGIFView =(MYGIFView)findViewById(R.id.myGifImageView);
mMYGIFView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
通过使用此您的GIF图像会显示在两个模拟器和真实设备:)
By using this your GIF image will show on both emulator and real device :)
这篇关于GIF图像的工作模拟器上,但不是在真实的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!