我有一个像这样的图像视图
<ImageView
android:layout_width = "wrap_content"
android:layout_height="wrap_content"
android:src = "@drawable/myimage"/>
图像文件“myimage.png”位于不同密度的所有4个可绘制文件夹中。这个视图看起来很不错。如果我在平板电脑上显示它(例如10英寸),那么图像“看起来”太小,因为空间太大。
我知道我可以为大屏幕尺寸创建布局,但是我在哪里放置更大尺寸的图像文件?这样,不仅可以根据密度而且可以根据屏幕尺寸选择图像文件
谢谢
答案 0 :(得分:1)
您应该使用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
答案 1 :(得分:0)
屏幕尺寸特定资源由small
,medium
,large
和xlarge
表示。所以你需要一个drawable-small
和/或layout-small
文件夹等。
来源:https://developer.android.com/guide/practices/screens_support.html
编辑:屏幕尺寸文件夹自Android 3.2以来已被弃用。请使用密度文件夹答案 2 :(得分:0)
简单步骤: -
如果您使用的是股票图标。转到此网站https://material.io/icons/。选择并下载大小为48dp的图标。
解压缩zip文件并选择android下的所有文件夹并将其复制到项目的res文件夹中。就是这样。
答案 3 :(得分:0)
一种棘手的方法是将imageView的scaleType设置为fitcenter,并为imageview设置恒定的宽度和高度。它会将您的图标放大到指定的宽度和高度
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:scaleType="fitCenter"
android:src="@drawable/my_photo"/>