我希望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放置在某個位置。 –
我剛剛用我在另一個線程中發現的最新代碼更新了主帖。根據他們這個代碼應該工作,但由於某種原因,它不適合我。 –