我想做一个简单的“游戏”是在一些网格中向上、向下、向左或向右移动的圆圈(不可点击,只是一个
ImageView
). 我想添加同一图像中只有一个imageview的多个
我试图找到最简单的方法,如下所示:
Integer img = R.drawable.trans_grid_2;
ImageView iView = new ImageView(this);
iView.setImageResource(img);
constraintLayout.addView(iView);
constraintLayout.addView(iView); //Cannot add 2 or more of the same Image
这给了我一个错误
(启动时应用程序崩溃)
:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
它表示我必须在重新使用它之前调用removeview()。但是,我想在java中添加多个相同的图像,而不需要复杂的东西。我不能添加同一个图像视图超过两次
我试过用谷歌搜索这个,但它显示了一些复杂的方式,而不是我需要的。
如何在Java中添加两个或多个相同的ImageView?