I have problem with displaying GIF on Samsung Galaxy Note 2 (Android 4.1.1) in my app. Everything is fine on Galaxy Nexus 7 emulator and others. Here is my source code:
public class ShouldersEx1 extends Activity {
View view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = findViewById(R.id.image_arms_ex1);
setContentView(R.layout.shoulders_ex1);
}
}
public class GIFView extends View {
private Movie movie;
private long moviestart;
public GIFView(Context context) throws IOException {
super(context);
movie = Movie.decodeStream(getResources().getAssets().open("barki1.gif"));
}
public GIFView(Context context, AttributeSet attrs) throws IOException {
super(context, attrs);
movie = Movie.decodeStream(getResources().getAssets().open("barki1.gif"));
}
public GIFView(Context context, AttributeSet attrs, int defStyle) throws IOException {
super(context, attrs, defStyle);
movie = Movie.decodeStream(getResources().getAssets().open("barki1.gif"));
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
long now = android.os.SystemClock.uptimeMillis();
Paint p = new Paint();
p.setAntiAlias(true);
if (moviestart == 0)
moviestart = now;
int relTime;
relTime = (int) ((now - moviestart) % movie.duration());
movie.setTime(relTime);
movie.draw(canvas, 0, 0);
this.invalidate();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.personaltrainer.utils.GIFView
android:id="@+id/image_arms_ex1"
android:layout_width="320dp"
android:layout_height="240dp"
android:layout_gravity="center"
android:layout_marginLeft="30dp" >
</com.personaltrainer.utils.GIFView>
<TextView
android:id="@+id/tresc_informacje"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shoulders_ex1"
android:textSize="20sp"
android:layout_margin="3dp"/>
What can be wrong? Please notice that on every screen I have following error:
01-04 02:12:06.250: E/SpannableStringBuilder(29691): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
Ok, as far as I know there is no workaround for it. Here is an officially reported issue: http://code.google.com/p/android/issues/detail?id=3422
GIF doesn't work on Android 4.1 and newer, despite the fact that on the Android emulator it works on every Android version.
Possible solutions I see:
wait for Android developers to resolve this issue
split every GIF into separate frames and "manually" change it every 200 ms or similar
来源:https://stackoverflow.com/questions/14149852/gif-doesnt-display-on-samsung-galaxy-note-2