我有一张更大的 1024 x 768 图像。当图像作为背景图像显示在 android 设备中时,它会被压缩。有什么方法可以在所有屏幕分辨率下正确显示图像?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:background = "@drawable/titlepage">
</RelativeLayout>
这是我用来设置背景图片的代码。但由于图像非常大,在模拟器或设备上查看时似乎被压缩了。
任何帮助都会很棒。
最佳答案
你说的是多屏幕支持。您需要制作 3 种类型的图像,HDPI、MDPI 和 LDPI。它们具有不同的纵横比和不同的尺寸。
看看我关于这个主题的教程,应该解释一切。
http://wonton-games.blogspot.com/2010/07/tutorial-multiple-screen-support.html
或者如果你只是想保持你的宽高比,一个更简单的方法是在你的 xml 文件中使用 imageView 做这个
<ImageView
android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/background"
android:adjustViewBounds="true">
</ImageView>
这样做的目的是保持图像的纵横比并使其适合屏幕。如果纵横比不匹配,您会在两侧看到横条,但这只是一种快捷方式。您可能需要调整 layout_width/height 以使其适合。
关于android - 最好将较大的图像放入 android 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3981427/