您好我试图用我的手机内存中的Bitmap开始一个AnimationDrawable:
public void startAnimation(JSONArray listImgGroup, RelativeLayout rl) throws JSONException {
if (listImgGroup.length() > 0) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
for (int i = 0; i < listImgGroup.length(); i++) {
ImageView imgGroup = new ImageView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) (metrics.widthPixels * listImgGroup.getJSONObject(i).getDouble("size_x")), (int) (metrics.heightPixels * listImgGroup.getJSONObject(i).getDouble("size_y")));
params.leftMargin = (int) (metrics.widthPixels * listImgGroup.getJSONObject(i).getDouble("position_x"));
params.topMargin = (int) (metrics.heightPixels * listImgGroup.getJSONObject(i).getDouble("position_y"));
JSONArray imgDic = listImgGroup.getJSONObject(i).getJSONArray("Img");
Log.i("IMG DICTIONNAIRE = ", "" + imgDic);
for (int j = 0; j < imgDic.length(); j++) {
//Bitmap bMap = BitmapFactory.decodeFile("/storage/sdcard0/saved_img/"+imgDic.getJSONObject(j).getString("name"));
animation = new AnimationDrawable();
animation.addFrame(new BitmapDrawable(getResources(), BitmapFactory.decodeFile("/storage/sdcard0/saved_img/"+imgDic.getJSONObject(j).getString("name"))), 1000);
animation.setCallback(imgGroup);
animation.start();
imgGroup.setImageDrawable(animation);
animation.setOneShot(false);
Log.i("NAME ANIMATION", imgDic.getJSONObject(j).getString("name"));
}
rl.addView(imgGroup, params);
animation.stop();
}
}
它可以工作,但我只看到我的AnimationDrawable中的第二个图像。我怎样才能看到第一个并将第一个动画转到第二个?谢谢你的家伙