简体   繁体   English

了解支持与图像有关的不同屏幕尺寸

[英]Understanding supporting different screen sizes relating to Images

I still have problems with the correct view for the images in my Application. 我在应用程序中对图像的正确视图仍然存在问题。 So on my first device (5,2 inches & 480 density) it looks good. 因此,在我的第一台设备(5,2英寸和480密度)上,它看起来不错。

在此处输入图片说明

On the second device (5,5 inches & 420 density) the image doesn't fit and it shows white borders. 在第二台设备(5.5英寸和420密度)上,图像不合适,并且显示白色边框。

在此处输入图片说明

This is the ImageView in my layout: 这是我布局中的ImageView:

  <ImageView
    android:id="@+id/iv_image"
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"   
    android:layout_alignParentStart="true" 
    android:layout_below="@id/tv_topic" />

I placed all my Images in the drawable folder after reading this on a Android Blog : Android博客上阅读以下内容后,我将所有图片都放在了drawable文件夹中:

There are commonly two ways to target all screen DPIs. 通常,有两种方法可以将所有屏幕DPI作为目标。 1. Easiest way - Make all images to Extra High or Extra Extra High DPI. 1.最简单的方法-使所有图像达到超高或超高DPI。

Android auto-scales the drawables if the device does not match the drawable DPI. 如果设备与可绘制DPI不匹配,则Android自动缩放可绘制。 If the only drawables are created in high density, lower DPI screens will down-scale a resource to fit in a layout. 如果仅以高密度创建可绘制对象,则较低的DPI屏幕将按比例缩小资源以适合布局。

So I implemented all Images in the highest possible resolution ONCE in the drawable folder. 因此,我在可绘制文件夹中以尽可能最高的分辨率实施了所有图像。 Is it necessary to place them all in the specific folders (drawable-ldpi, drawable-mdpi ...)? 是否有必要将它们全部放在特定的文件夹中(drawable-ldpi,drawable-mdpi ...)? It would mean that there will be multiple copies of my Image with always the same size. 这意味着将有我的图像的多个副本,并且始终具有相同的大小。

And yes I read the official documentation of supporting multiple screens a couple times. 是的,我几次阅读了支持多个屏幕的官方文档。 However I have some problems understanding it. 但是我在理解它时有一些问题。

I advice you to use the layout_weight attribute to keep the constant ratio between the ImageView and the question layout. 我建议您使用layout_weight属性来保持ImageView和问题布局之间的恒定比率。 Change your layout to something like this : 将布局更改为以下内容:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="4">
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <ImageView
            android:id="@+id/iv_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </LinearLayout>
    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="0dp"
        android:layout_weight="3" />
</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM