I set a single image (640x960) as follows:
<?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>
Notice the scaleType is "center" which according to documentation means no scaling. When running on Nexus 5x, this image looks a lot bigger than the screen and is only partially displayed.
I read about android not using resolution directly. Then the question is how to calculate the size of an image that should fit the screen of a particular android device without scaling.
I understand Nine Patch image can be used to create splash images that will not distort the portion of image that should not be scaled. This question is partly for myself to better understand how image pixels relate to the screen of an actual device, and if using Nine Patch image is the only way to guarantee that the splash images will work on android devices of any screen dimensions.
Many thanks
scaleType centerInside should do the trick without having to make calculations in code
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/launch_image"
android:scaleType="centerInside"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.