我设置了单个图像(640x960),如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.imagetest.MainActivity"
tools:showIn="@layout/activity_main">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/launch_image"
android:scaleType="center"/>
</RelativeLayout>请注意,scaleType是“中心”,根据文档,这意味着没有缩放。在Nexus 5x上运行时,此图像看起来比屏幕大得多,并且仅部分显示。
我读到过android没有直接使用分辨率。然后,问题是如何计算图像的大小,使其适合特定android设备的屏幕而不进行缩放。
我知道九补丁图像可以用来创建不会扭曲不应该缩放的图像部分的启动图像。这个问题在一定程度上是为了更好地理解图像像素与实际设备的屏幕之间的关系,以及使用Nine Patch图像是不是保证启动图像在任何屏幕尺寸的android设备上都能工作的唯一方法。
非常感谢
发布于 2016-08-26 21:01:13
scaleType centerInside应该可以做到这一点,而不必在代码中进行计算
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/launch_image"
android:scaleType="centerInside"/>https://stackoverflow.com/questions/39166936
复制相似问题