我希望myImageView能够在屏幕内的任意位置找到自己的位置,而不用将文本视图移开。我在另一个线程中发现了这个代码,但我无法使其工作。随机位置上的Imageview
myImageView = (ImageView) findViewById(R.id.myImageView);
LinearLayout game = (LinearLayout)findViewById(R.id.game);
int width = game.getWidth();
int height = game.getHeight();
random = new Random();
int x = width;
int y = height;
int imageX = random.nextInt(x-50)+50;
int imageY = random.nextInt(y-100)+100;
myImageView.setX(imageX);
myImageView.setY(imageY);
'Math.random()'是你的朋友。 – rekire
这不是问题所在。问题是,我不知道使用什么方法将imageview放置在某个位置。 –
我刚刚用我在另一个线程中发现的最新代码更新了主帖。根据他们这个代码应该工作,但由于某种原因,它不适合我。 –