嗨,我正在尝试在我的手机内存中使用 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 中看到第二张图像。我怎样才能看到第一个并将第一个动画化到第二个?谢谢你