屏幕分辨率与图片问题

时间:2015-12-24 01:26:00

标签: android image android-layout density-independent-pixel screen-density

我已经在应用程序上工作了一段时间,现在创建了一个拼图拼图。我正在测试各种尺寸和密度的屏幕。使用Krita我将平铺图像缩小到110 X 110像素,以便在mdpi格式中使用。奇怪的是,这个大小在我迄今为止用于测试的xhdpi模拟器中工作得很好,但是我创建的mdpi模拟器显着缩小了图像。虽然我可以为较小的屏幕密度创建更大的图像,但它违背了我对android如何处理文档中的密度的理解。难道这些图像不应该在较低分辨率下被炸毁吗?这是布局文件的网格布局部分:

    <GridLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:columnCount="3"
    android:rowCount="3"
    android:id="@+id/TheGrid"
    android:layout_centerInParent="true"
    android:background="@color/background_floating_material_light"
    android:animateLayoutChanges="true"
    android:layout_toRightOf="@+id/title_inflater"
    android:layout_toLeftOf="@+id/picture_inflator"
    >

    <ImageView
        android:id="@+id/TopLeft"
        android:clickable="true"
        android:layout_column="0"
        android:layout_row="0"
        android:layout_gravity="fill"
        android:src="@drawable/star_trek_federation_emblem_9pc_1"
        />
    <ImageView
        android:id="@+id/TopCenter"
        android:clickable="true"
        android:layout_gravity="fill"
        android:layout_row="0"
        android:layout_column="1"
        android:src="@drawable/star_trek_federation_emblem_9pc_1"
        />
    <ImageView
        android:id="@+id/TopRight"
        android:clickable="true"
        android:layout_gravity="fill"
        android:layout_row="0"
        android:layout_column="2"
        android:src="@drawable/star_trek_federation_emblem_9pc_1"
        />


    <ImageView
        android:id="@+id/CenterLeft"
        android:clickable="true"
        android:layout_gravity="fill"
        android:layout_row="1"
        android:layout_column="0"
        android:src="@drawable/star_trek_federation_emblem_9pc_1"
        />

    <ImageView
        android:id="@+id/CenterCenter"
        android:clickable="true"
        android:layout_gravity="fill"
        android:layout_row="1"
        android:layout_column="1"
        android:src="@drawable/star_trek_federation_emblem_9pc_1"
        />
    <ImageView
        android:id="@+id/CenterRight"
        android:clickable="true"
        android:layout_gravity="fill"
        android:layout_row="1"
        android:layout_column="2"
        android:src="@drawable/star_trek_federation_emblem_9pc_1"
        />

    <ImageView
        android:id="@+id/BottomLeft"
        android:clickable="true"
        android:layout_gravity="fill"
        android:layout_row="2"
        android:layout_column="0"
        android:src="@drawable/star_trek_federation_emblem_9pc_1"
        />
    <ImageView
        android:id="@+id/BottomCenter"
        android:clickable="true"
        android:layout_gravity="fill"
        android:layout_row="2"
        android:layout_column="1"
        android:src="@drawable/star_trek_federation_emblem_9pc_1"
        />
    <ImageView
        android:id="@+id/BottomRight"
        android:clickable="true"
        android:layout_gravity="fill"
        android:layout_row="2"
        android:layout_column="2"
        android:src="@drawable/star_trek_federation_emblem_9pc_1"
        />

    <ImageView
        android:id="@+id/mover"
        android:layout_row="2"
        android:layout_column="2"
        android:visibility="invisible"
        android:layout_gravity="fill"
        />
</GridLayout>

这就是它在预览器中的外观(它在xhdpi屏幕上的外观):

enter image description here

然后在mdpi屏幕中看起来像:

enter image description here

我想在我盲目调整图像之前知道为什么会发生这种情况,但是在创建各种模拟器和搜索网络的大部分时间之后我都陷入了困境。任何帮助都将非常感激。

1 个答案:

答案 0 :(得分:1)

1)第一种方式您可以从此链接创建所有尺寸的图像 https://romannurik.github.io/AndroidAssetStudio/只需将图片上传到此网站,您就可以获得所有尺寸的所有尺寸图片。它可以帮助您调整所有尺寸。

或者如果你不喜欢第一种方式,你可以使用

:此 第二种方式 要创建不同密度的图标,您应该遵循四个主要密度(分别为中,高,x高和xx高)之间的2:3:4:6缩放比例。

例如,请考虑启动器图标的大小指定为48x48 dp。

这意味着基线(MDPI)资产为48x48像素,

且高密度(HDPI)资产应为基线的1.5倍,为72x72像素,

并且x高密度(XHDPI)资产应该是96x96像素的基线的2倍,依此类推。

注意:Android还支持资产规模为36x36像素的低密度(LDPI)屏幕,但您通常不需要创建此大小的自定义资源,因为Android会有效地将您的HDPI资产缩减1/2以匹配预期的大小。

同样,XXHDPI资产规模应为144x144像素。

来源:developer.android.com