2017-06-19 51 views
0

我有一个ImageView的就是这个样子放在哪里绘制的图像为特定屏幕大小

<ImageView 
android:layout_width = "wrap_content" 
android:layout_height="wrap_content" 
android:src = "@drawable/myimage"/> 

图像文件“myimage.png”是在不同的密度的所有4个绘制文件夹。这个视图在手机上看起来不错。如果我在平板电脑上显示它(例如10英寸),则图像“看起来”太小,因为有太多空间。

我知道我可以为大屏幕尺寸创建布局,但我在哪里放置图像文件的大尺寸?通过这种方式,图像文件可以基于不仅密度采摘也是屏幕尺寸

谢谢

回答

0

您应该使用sw符号。

例如:

layout/activity_with_photo.xml 
layout-sw600dp/activity_with_photo.xml // that's a 7 inch tablet 
layout-sw720dp/activity_with_photo.xml // that's a nexus 9 and up 

,然后这些布局更大的图像

// here a 7 inch tabled with all the densities 
layout-mdpi-sw600dp/photo.png 
layout-hdpi-sw600dp/photo.png 
layout-xdpi-sw600dp/photo.png 
layout-xxdpi-sw600dp/photo.png 

// here a nexus 9 n up with all densities 
layout-mdpi-sw720dp/photo.png 
layout-hdpi-sw720dp/photo.png 
layout-xdpi-sw270dp/photo.png 
layout-xxdpi-sw720dp/photo.png 

另外,如果你在运行时做这些资源的适当的比例,你可以添加到no-dpi文件夹

layout-nodpi-sw600dp/photo.png 
layout-nodpi-sw270dp/photo.png 

但是,如果您只使用一个,请注意这里:Bitmap too large to be uploaded into a texture

0

屏幕尺寸的特定资源由smallmediumlargexlarge表示。所以你需要一个drawable-small和/或layout-small文件夹等

来源:https://developer.android.com/guide/practices/screens_support.html

编辑:由于Android 3.2屏幕尺寸文件夹已过时。请使用密度文件夹

+0

哦我不知道你可以使用屏幕大小以及可绘制的名称。所以,如果你有可绘制的小图和drawable-xdpi的图像,那么在一个小的xdpi屏幕上,从哪个文件夹获取图像? – Snake

+0

我刚刚注意到这些已被弃用。请使用密度文件夹 – Aenadon

0

简单的步骤: -

  1. 如果您正在使用股票的图标。去这个网站https://material.io/icons/。选择并下载大小为48dp的图标。

  2. 提取zip文件并选择android下的所有文件夹,并将它们复制到项目的res文件夹中。而已。

enter image description here

+0

我不问密度。我在询问屏幕尺寸 – Snake

+0

转到res> values>添加新文件命名'维度'>在限定符中选择'尺寸',并从小到大选择'屏幕尺寸'。然后在新(x-large)维度文件下添加大屏幕维度。 –

0

一个棘手的方式设置的ImageView到fitcenter的scaleType和恒定的宽度和高度设置为您的ImageView。将你的图标扩展到指定的宽度和高度

<ImageView 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    android:scaleType="fitCenter" 
    android:src="@drawable/my_photo"/> 
相关问题