从Android 4.3(Jelly Bean)开始,我们现在可以利用这些res/mipmap
文件夹来存储"mipmap"图像.
例如,Chrome for Android将其图标存储在这些文件夹中,而不是更常用的res/drawable
文件夹中.
这些mipmap图像与其他熟悉的可绘制图像有何不同?
我看到在我的清单中,我们使用@mipmap/
限定符,而不是@drawable/
,这对于资源文件夹名称是有意义的:
<activity
android:name=".MipmapDemp"
android:icon="@mipmap/ic_launcher" />
Run Code Online (Sandbox Code Playgroud)
在Android 4.3的API的文档具有下面要说:
使用mipmap作为位图或drawable的源是提供高质量图像和各种图像比例的简单方法,如果您希望在动画期间缩放图像,这可能特别有用.
Android 4.2(API级别17)在Bitmap类中添加了对mipmap的支持 - 当您提供了mipmap源并启用了setHasMipMap()时,Android会在您的Bitmap中交换mip图像.现在在Android 4.3中,您还可以通过提供mipmap资源并在位图资源文件中设置android:mipMap属性或通过调用hasMipMap()来为BitmapDrawable对象启用mipmaps.
我没有看到任何有助于我理解的东西.
XML Bitmap资源具有以下android:mipMap
属性:
布尔.启用或禁用mipmap提示.有关更多信息,请参见setHasMipMap().默认值为false.
就我所见,这不适用于启动器图标.
问题出现在Google网上论坛(资源名称"mipmap"的目的?!)上,Romain Guy回复道:
提供通常可以计算的更大分辨率的图像很有用(例如,在mdpi设备上,Launcher可能希望更大的hdpi图标显示大型应用程序快捷方式.)
我觉得这几乎是有意义的,但并不完全.
我仍然倾向于选择Randy Sugianto的跟进:
这有什么好处?是否有任何指南如何使用mipmap,可能是为了更好的启动器图标?
当然,维基百科有一个"Mipmap"页面,它指的是一种1983年发明的旧技术,我无法与当前的Android实现相关联.
我们现在应该将所有应用程序图标res/mipmap
存储在文件夹中吗?这些mipmap图像的准则是什么?
更新#1
这是一篇博文,试图解释一下.
但是该博客文章中使用的图像显示了一个包含许多徽标的文件.这不是我在Chrome的mipmap文件夹中看到的.
Chrome的mipmap-hdpi
文件夹包含三张图片.一个是Chrome徽标,单独使用.
奇怪的是,它是72x72,而不是48x48,我希望看到.
也许这就是全部 - 我们只需要在mipmap文件夹中保留更大的图标?
更新#2
2014年10月23日的Android开发者博客文章再次证实了将mipmap
文件夹用于应用程序图标的想法:
我想知道如何更改Android Studio中的启动器图标.我非常感谢你能给我的任何建议.
在Android Studio中,我无法确定在应用程序中放置图像的位置.drawable文件夹没有分解为drawable-hdpi,drawable-ldpi等.我看到了另一个问题,答案是切换到Project视图而不是Android视图,但drawable只有一个文件夹.有mipmap-hdpi,mipmap-ldpi等,但人们都说这只适用于app图标.我糊涂了.
我使用的是Design Support Library版本23.4.0.我启用了gradle标志:
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
Run Code Online (Sandbox Code Playgroud)
我正在使用构建工具版本23.0.2,但仍然,我正在Resources$NotFoundException
使用KitKat或更低版本.
它发生在我使用android:drawableLeft
或时imageView.setImageResource(R.drawable.drawable_image)
.
是的,我把它放在我使用drawables的每个活动上
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)
这是支持库的错误吗?
android android-support-library androiddesignsupport android-vectordrawable
我有一个已发布的应用程序,当新引入的Display size
操作系统设置设置为太大值时,在Android N上启动时崩溃.
当我查看logcat时,我看到以下消息:
java.lang.RuntimeException: Canvas: trying to draw too large(106,975,232 bytes) bitmap.
Run Code Online (Sandbox Code Playgroud)
我在第一个Activity中将问题跟踪到ImageView,它显示了一个漂亮的大背景图像.有问题的图像是2048x1066,位于我的通用drawables
目录中,因此无论密度如何,都将使用此图像.
当Display size
设置为时,一切正常Small
.但是当我上去时Default
,它就会停止工作.如果我然后用较小的图像交换图像,它可以工作Default
,但如果我去Large
,它会再次停止工作.
我的猜测是,调整Display size
会使您的设备表现得像具有更高像素密度的物理上更小的设备.但我不明白我应该在这做什么.如果我逐渐增加较小的图像以逐渐提高分辨率,那么在实际大型显示器上看起来不会很好.或者我不明白什么?
任何指针都将非常感激.
嗨,根据Android文档,drawable文件夹需要有不同dpis图像的多个子目录.但是在Android Studio中,在drawable文件夹中创建任何子目录会导致它无法检测到任何图像.另一方面,如果图像直接放在drawable文件夹中,它将被检测到并可用于查看R.drawable.ImageName.在这种情况下,我们如何为同一个ImageName使用不同的dpi图像?
我替换了所有图像到处(我的意思是在drawable文件夹和所有Windows资源文件夹和iOS资源文件夹中),但它仍然显示应用程序的默认Xamarin图标.我也试过这个代码,但它似乎也没有用.有人能告诉我解决方案吗?
[assembly: Application(Icon = "@drawable/icon")]
Run Code Online (Sandbox Code Playgroud) 如何以mipmap
编程方式从文件夹加载图像(与drawables一样)?
img.setImageResource(imageId);
Run Code Online (Sandbox Code Playgroud)
我使用的是Android Studio 1.2.1.
我的ImageView
布局中有一个,见下面的代码.当我尝试将该src
属性设置为我的启动器图标时,我收到以下错误:
Cannot resolve symbol '@drawable/ic_launcher'
Run Code Online (Sandbox Code Playgroud)
ic_launcer.png被添加到我的drawables文件夹中,见下图.为什么我不能在我的图像中引用我的图像ImageView
?
项目结构:
Layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)