Android - 将图像定位在准确位置
Android - Positioning an image at exact location
我正在尝试在我的 android 应用程序中定位图像,以便它显示在屏幕宽度的中间和屏幕高度的下部。我需要它看起来像这样。
我的图片是 200x50,所以我使用了以下逻辑来实现。
Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.play), screenWidth/2 - 100, 3*screenHeight/4 - 25, null);
但我仍然没有定位到正确的位置,我是这样定位的。
我这里做错了什么?我该怎么做?
为什么需要为此编写 java 代码?
只需指定 xml 中的属性。
center horizontal = true and margin bottom = "some value"
完成
试试这个
alignParentBottom - true
centerHorizontal - true
marginBottom (Calculate 15% of height and set it)
你能试试这个吗
Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
Bitmap playImage = BitmapFactory.decodeResource(getResources(), R.drawable.play);
canvas.drawBitmap(playImage, (screenWidth/2) - (playImage.getWidth()/2), 3*screenHeight/4 - 25, null);
我正在尝试在我的 android 应用程序中定位图像,以便它显示在屏幕宽度的中间和屏幕高度的下部。我需要它看起来像这样。
我的图片是 200x50,所以我使用了以下逻辑来实现。
Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.play), screenWidth/2 - 100, 3*screenHeight/4 - 25, null);
但我仍然没有定位到正确的位置,我是这样定位的。
我这里做错了什么?我该怎么做?
为什么需要为此编写 java 代码?
只需指定 xml 中的属性。
center horizontal = true and margin bottom = "some value"
完成
试试这个
alignParentBottom - true
centerHorizontal - true
marginBottom (Calculate 15% of height and set it)
你能试试这个吗
Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
Bitmap playImage = BitmapFactory.decodeResource(getResources(), R.drawable.play);
canvas.drawBitmap(playImage, (screenWidth/2) - (playImage.getWidth()/2), 3*screenHeight/4 - 25, null);