我在我的应用程序中的三星 Galaxy Note 2 (Android 4.1.1) 上显示 GIF 时遇到问题。Galaxy Nexus 7 模拟器和其他模拟器上的一切都很好。这是我的源代码:
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"/>
有什么问题?请注意,在每个屏幕上我都有以下错误:
01-04 02:12:06.250: E/SpannableStringBuilder(29691): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length