需要建议在android中计算背景图像的长度和宽度吗

需要建议在android中计算背景图像的长度和宽度吗,android,android-layout,background,Android,Android Layout,Background,在我的android应用程序中,我有一个背景图像,它比所有三种屏幕的屏幕宽度都长。这意味着我有3个不同屏幕类型(mdpi、ldpi、hdpi)的可绘制图像,因此我的应用程序中包含了一个水平滚动条 现在我想知道实际的背景图像在可见屏幕之外延伸了多少。我该如何计算呢 屏幕上可见的背景图像的实际宽度和高度是否与可绘图文件夹中图像的尺寸相同,或者我是否需要计算此值。如果是,请告诉我如何在此类情况下计算背景图像的尺寸。好的,您可以从以下内容获得图像的尺寸: Bitmap bitmap = BitmapFa

在我的android应用程序中,我有一个背景图像,它比所有三种屏幕的屏幕宽度都长。这意味着我有3个不同屏幕类型(mdpi、ldpi、hdpi)的可绘制图像,因此我的应用程序中包含了一个水平滚动条

现在我想知道实际的背景图像在可见屏幕之外延伸了多少。我该如何计算呢


屏幕上可见的背景图像的实际宽度和高度是否与可绘图文件夹中图像的尺寸相同,或者我是否需要计算此值。如果是,请告诉我如何在此类情况下计算背景图像的尺寸。

好的,您可以从以下内容获得图像的尺寸:

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.image_resource);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenWidth = displaymetrics.widthPixels; 
int screenHeight = displaymetrics.heightPixels;
您可以通过以下方式获得屏幕的尺寸:

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.image_resource);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenWidth = displaymetrics.widthPixels; 
int screenHeight = displaymetrics.heightPixels;
现在你可以计算了