图像出现在屏幕android

时间:2014-06-29 01:34:13

标签: java android

我正在尝试在屏幕上移动图像,但有时图像会显示在屏幕的一半或完全关闭。 我的代码如下:

width = image.getWidth();
height = image.getHeight();
main = (RelativeLayout) findViewById(R.id.mainLayout);
screenWidth = main.getWidth();
screenHeight = main.getHeight();
xCalc = screenWidth - width;
yCalc = screenHeight - height;
imageParams = (RelativeLayout.LayoutParams) image.getLayoutParams();
Random rand = new Random();

xValue = (int) (rand.nextFloat() * xCalc);
yValue = (int) (rand.nextFloat() * yCalc);
imageParams.setMargins(xValue, yValue, 0, 0);
image.setLayoutParams(dotParams);

0 个答案:

没有答案