Android Studio:可绘制文件夹:如何为多个dpi放置图像?

时间:2021-12-18 06:11:48

Hi as per android documentation the drawable folder needs to have multiple sub-directories for images of different dpis. However in Android Studio creating any sub directory in the drawable folder causes it to fail to detect any images at all. On the other hand if an image is placed directly in the drawable folder it gets detected and becomes available for use view R.drawable.ImageName. In this case how do we use different dpi images for the same ImageName?

嗨,根据Android文档,drawable文件夹需要有多个子目录,用于不同dpis的图像。但是在Android Studio中,在drawable文件夹中创建任何子目录会导致它无法检测到任何图像。另一方面,如果图像直接放在drawable文件夹中,它将被检测到并可用于查看R.drawable.ImageName。在这种情况下,我们如何为同一ImageName使用不同的dpi图像?

9 个解决方案

#1


86  

The standard procedures are:

标准程序是:

  1. Choose Project > app > scr > main
  2. 选择Project> app> scr> main
  3. Right click "res", choose "New" and choose "Android resource directory" Android Studio:可绘制文件夹:如何为多个dpi放置图像?
  4. 右键单击“res”,选择“新建”并选择“Android资源目录”
  5. In the opened dialog, at Resource Type choose "drawable" Android Studio:可绘制文件夹:如何为多个dpi放置图像?
  6. 在打开的对话框中,在资源类型中选择“可绘制”
  7. In the list Available qualifier choose Density, then click the right arrow at the middle. Android Studio:可绘制文件夹:如何为多个dpi放置图像?
  8. 在可用限定符列表中选择“密度”,然后单击中间的右箭头。
  9. Choose the Density that you like then press OK Android Studio:可绘制文件夹:如何为多个dpi放置图像?
  10. 选择您喜欢的密度,然后按OK

#2


21  

There are two ways of doing it.

有两种方法可以做到这一点。

1.Right click on drawable New->Image Asset-> select your highest resolution image rest will be created automatically. once you finish you can see different resolution inside drawable folder

1.右键单击drawable New-> Image Asset->选择最高分辨率的图像,将自动创建。完成后,您可以在drawable文件夹中看到不同的分辨率

  1. The way you want. on the project Explorer window you see a dropdown as Android. Click it change to project.
  2. 你想要的方式。在项目资源管理器窗口中,您会看到Android下拉列表。单击它更改为项目。

Now yourprojectname->app->src->main->res->

现在你的项目名称 - > app-> src-> main-> res->

Aila You can see your drawable folders with hdpi mdpi etc.

Aila您可以使用hdpi mdpi等查看您的可绘制文件夹。

#3


11  

You don't create subfolders of the drawable folder but rather 'sibling' folders next to it under the /res folder for the different screen densities or screen sizes. The /drawable folder (without any dimension) is mostly used for drawables that don't relate to any screen sizes like selectors.

您不创建可绘制文件夹的子文件夹,而是创建/ res文件夹下的“兄弟”文件夹,以用于不同的屏幕密度或屏幕大小。 / drawable文件夹(没有任何尺寸)主要用于与选择器等任何屏幕尺寸无关的可绘制文件。

See this screenshot (use the name drawable-hdpi instead of mipmap-hdpi):

请参阅此屏幕截图(使用名称drawable-hdpi而不是mipmap-hdpi):

Android Studio:可绘制文件夹:如何为多个dpi放置图像?

#4


8  

Simply go to project Explorer and change your View from Android to project from drop Down and you are good to go.There you can simply create folder like we do in Eclipse. And in android project view it is hidden but when you switch to project. You can create folder like drawable-hdpi,drawable-xhdpi.

只需转到项目资源管理器,然后从下拉菜单中将您的View从Android更改为项目即可。您可以像在Eclipse中一样创建文件夹。并且在android项目视图中它被隐藏但是当你切换到项目时。您可以创建像drawable-hdpi,drawable-xhdpi这样的文件夹。

Android Studio:可绘制文件夹:如何为多个dpi放置图像?

#5


8  

The easiest way I have found to have the proper "directory" structure appear under the drawable folder for my icons is this:

我发现有最合适的“目录”结构的方法出现在我的图标的drawable文件夹下面是这样的:

  1. Right click "Drawable"
  2. 右键单击“Drawable”
  3. Click on "New", then "Image Asset"
  4. 点击“新建”,然后点击“图片资产”
  5. Change "Asset Type" to "Action Bar and Tab Icons"
  6. 将“资产类型”更改为“操作栏和选项卡图标”
  7. For "Foreground" choose "ClipArt"
  8. 对于“前景”选择“ClipArt”
  9. For "Clipart" click and "Choose" button and pick any icon
  10. 对于“剪贴画”,单击“选择”按钮并选择任何图标
  11. For "Resource Name" type in you icon file name
  12. 对于“资源名称”,在图标文件名中键入

Now the pseudo-directories have been created for you under the Drawable folder in the Android view. Open up the true directories on your file system "main/res/drawable-xxhdpi", "main/res/drawable-xhdpi" and replace the icons in each folder with your own of the proper density.

现在,已在Android视图的Drawable文件夹下为您创建了伪目录。打开文件系统“main / res / drawable-xxhdpi”,“main / res / drawable-xhdpi”上的真实目录,并用您自己的密度替换每个文件夹中的图标。

#6


0  

In android studio you may see the following folder drawable xhdpi, drawable-hdpi, drawable-mdpi and more... You can put images of different dpi in these folder accordingly and android will take care which images should be draw according to the screen density of device.

在android studio中你可能会看到以下文件夹drawable xhdpi,drawable-hdpi,drawable-mdpi等...你可以相应地将不同dpi的图像放在这些文件夹中,android会照顾哪些图像应该根据屏幕密度绘制设备。

NOTE: You have to put the images with the same name.

注意:您必须使用相同的名称放置图像。

#7


0  

simply copy and paste the image into res>drawable and it ask you destination folder which you want to pate resolution image for more help please look for Android Studio drawable folders

只需将图像复制并粘贴到res> drawable中,它会询问您想要获得分辨率图像的目标文件夹以获得更多帮助请查看Android Studio可绘制文件夹

#8


0  

You need to access image IDs using R.mipmap.yourImageName

您需要使用R.mipmap.yourImageName访问图像ID

#9


0  

New -> Batch Drawable Import -> Click on Add button -> Select image -> Select Target Resolution, Target Name, Format -> Ok

新建 - >批量可绘制导入 - >单击添加按钮 - >选择图像 - >选择目标分辨率,目标名称,格式 - >确定

#1


86  

The standard procedures are:

标准程序是:

  1. Choose Project > app > scr > main
  2. 选择Project> app> scr> main
  3. Right click "res", choose "New" and choose "Android resource directory" Android Studio:可绘制文件夹:如何为多个dpi放置图像?
  4. 右键单击“res”,选择“新建”并选择“Android资源目录”
  5. In the opened dialog, at Resource Type choose "drawable" Android Studio:可绘制文件夹:如何为多个dpi放置图像?
  6. 在打开的对话框中,在资源类型中选择“可绘制”
  7. In the list Available qualifier choose Density, then click the right arrow at the middle. Android Studio:可绘制文件夹:如何为多个dpi放置图像?
  8. 在可用限定符列表中选择“密度”,然后单击中间的右箭头。
  9. Choose the Density that you like then press OK Android Studio:可绘制文件夹:如何为多个dpi放置图像?
  10. 选择您喜欢的密度,然后按OK

#2


21  

There are two ways of doing it.

有两种方法可以做到这一点。

1.Right click on drawable New->Image Asset-> select your highest resolution image rest will be created automatically. once you finish you can see different resolution inside drawable folder

1.右键单击drawable New-> Image Asset->选择最高分辨率的图像,将自动创建。完成后,您可以在drawable文件夹中看到不同的分辨率

  1. The way you want. on the project Explorer window you see a dropdown as Android. Click it change to project.
  2. 你想要的方式。在项目资源管理器窗口中,您会看到Android下拉列表。单击它更改为项目。

Now yourprojectname->app->src->main->res->

现在你的项目名称 - > app-> src-> main-> res->

Aila You can see your drawable folders with hdpi mdpi etc.

Aila您可以使用hdpi mdpi等查看您的可绘制文件夹。

#3


11  

You don't create subfolders of the drawable folder but rather 'sibling' folders next to it under the /res folder for the different screen densities or screen sizes. The /drawable folder (without any dimension) is mostly used for drawables that don't relate to any screen sizes like selectors.

您不创建可绘制文件夹的子文件夹,而是创建/ res文件夹下的“兄弟”文件夹,以用于不同的屏幕密度或屏幕大小。 / drawable文件夹(没有任何尺寸)主要用于与选择器等任何屏幕尺寸无关的可绘制文件。

See this screenshot (use the name drawable-hdpi instead of mipmap-hdpi):

请参阅此屏幕截图(使用名称drawable-hdpi而不是mipmap-hdpi):

Android Studio:可绘制文件夹:如何为多个dpi放置图像?

#4


8  

Simply go to project Explorer and change your View from Android to project from drop Down and you are good to go.There you can simply create folder like we do in Eclipse. And in android project view it is hidden but when you switch to project. You can create folder like drawable-hdpi,drawable-xhdpi.

只需转到项目资源管理器,然后从下拉菜单中将您的View从Android更改为项目即可。您可以像在Eclipse中一样创建文件夹。并且在android项目视图中它被隐藏但是当你切换到项目时。您可以创建像drawable-hdpi,drawable-xhdpi这样的文件夹。

Android Studio:可绘制文件夹:如何为多个dpi放置图像?

#5


8  

The easiest way I have found to have the proper "directory" structure appear under the drawable folder for my icons is this:

我发现有最合适的“目录”结构的方法出现在我的图标的drawable文件夹下面是这样的:

  1. Right click "Drawable"
  2. 右键单击“Drawable”
  3. Click on "New", then "Image Asset"
  4. 点击“新建”,然后点击“图片资产”
  5. Change "Asset Type" to "Action Bar and Tab Icons"
  6. 将“资产类型”更改为“操作栏和选项卡图标”
  7. For "Foreground" choose "ClipArt"
  8. 对于“前景”选择“ClipArt”
  9. For "Clipart" click and "Choose" button and pick any icon
  10. 对于“剪贴画”,单击“选择”按钮并选择任何图标
  11. For "Resource Name" type in you icon file name
  12. 对于“资源名称”,在图标文件名中键入

Now the pseudo-directories have been created for you under the Drawable folder in the Android view. Open up the true directories on your file system "main/res/drawable-xxhdpi", "main/res/drawable-xhdpi" and replace the icons in each folder with your own of the proper density.

现在,已在Android视图的Drawable文件夹下为您创建了伪目录。打开文件系统“main / res / drawable-xxhdpi”,“main / res / drawable-xhdpi”上的真实目录,并用您自己的密度替换每个文件夹中的图标。

#6


0  

In android studio you may see the following folder drawable xhdpi, drawable-hdpi, drawable-mdpi and more... You can put images of different dpi in these folder accordingly and android will take care which images should be draw according to the screen density of device.

在android studio中你可能会看到以下文件夹drawable xhdpi,drawable-hdpi,drawable-mdpi等...你可以相应地将不同dpi的图像放在这些文件夹中,android会照顾哪些图像应该根据屏幕密度绘制设备。

NOTE: You have to put the images with the same name.

注意:您必须使用相同的名称放置图像。

#7


0  

simply copy and paste the image into res>drawable and it ask you destination folder which you want to pate resolution image for more help please look for Android Studio drawable folders

只需将图像复制并粘贴到res> drawable中,它会询问您想要获得分辨率图像的目标文件夹以获得更多帮助请查看Android Studio可绘制文件夹

#8


0  

You need to access image IDs using R.mipmap.yourImageName

您需要使用R.mipmap.yourImageName访问图像ID

#9


0  

New -> Batch Drawable Import -> Click on Add button -> Select image -> Select Target Resolution, Target Name, Format -> Ok

新建 - >批量可绘制导入 - >单击添加按钮 - >选择图像 - >选择目标分辨率,目标名称,格式 - >确定