如果您计划在不久的将来支持LDPI,MDPI,HPDI和XHDPI,那么只在项目中包含XHDPI drawable并让设备将它们扩展到所需的分辨率是否可以?
我已经测试过在Photoshop中将drawables调整为MDPI和HDPI,然后将结果与仅通过Android重新调整的XHDPI drawable进行比较,我看不出任何差别.采取这种捷径是不好的设计?不必将每个可绘制的大小调整为3种不同的分辨率是很好的.
计划使用目标SDK是2.1或2.2.
BR Emil
我最近在商店发布了一款Android应用程序,几乎适用于所有用户.但是,我很快就开始每周收到一些崩溃报告,其中包含以下跟踪:
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-xhdpi/dark_button_unpressed.png from drawable resource ID #0x7f02005d
at android.content.res.Resources.loadDrawable(Resources.java:1716)
at android.content.res.Resources.getDrawable(Resources.java:581)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1696)
... 40 more
Caused by: java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1711)
... 45 more
Run Code Online (Sandbox Code Playgroud)
要确定这里究竟发生了什么并不容易.我从用户报告中收集到的唯一一件事就是它似乎主要出现在低密度显示器的设备上.此特定资源用作XML UI中视图的背景.
我有一个将minSdkVersion设置为9 的Android应用程序.应用程序编译并运行,但是当它显示谷歌地图时,它崩溃了
android.content.res.Resources$NotFoundException: File res/drawable-mdpi-v4/maps_watermark_dark.png from drawable resource ID #0x7f02027c
Run Code Online (Sandbox Code Playgroud)
一切都指向播放服务库中缺少的资源.
我没有使用proguard,shrinkResources或resConfigs.
该设备是三星/ GT-S5360L/GT-S5360L:2.3.6/GINGERBREAD
这是相关部分 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
targetSdkVersion 21
minSdkVersion 9
versionCode 476
versionName "4.7.6"
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.1.71'
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的堆栈跟踪:
D/AndroidRuntime(10297): Shutting down VM
W/dalvikvm(10297): threadid=1: thread exiting with uncaught exception (group=0x40020578)
E/AndroidRuntime(10297): FATAL EXCEPTION: main
E/AndroidRuntime(10297): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.safertaxi.driver/driver.activities.driving.ActivityDriving}: android.view.InflateException: Binary XML file line …Run Code Online (Sandbox Code Playgroud) 除了平板电脑大小的屏幕,我的应用程序似乎在不同大小的屏幕上工作.
我的工作方式是使用相对布局,它有很多图像.然后,图像放入文件夹中的大小不同,将根据手机使用的图像(取决于大小)来拾取
我使用的文件夹是:
绘制,华电国际
绘制,MDPI
绘制,LDPI
^当我在eclipse中创建项目时,已经添加了这些.
我读了,并添加了drawable-xhdpi,期望更大的屏幕会使用它.然后我把图像放进去,我的布局在android 3.0模拟器上看起来很小.所以,然后我在xhdpi中的一个图像上放了一个标记,发现平板电脑模拟器实际上并没有使用这个图像.
有什么想法吗?清单中是否需要进行某些操作?
我在drawable概念中有一个查询.我有固定尺寸的图像,我把它们放在可绘制的文件夹中.我从eclipse项目中删除了我的其他文件夹,如drawable-hdpi,mdpi,ldpi,xhdpi,并制作了我的项目的APK.
我的问题是,我的应用程序(生成的apk)将在所有设备和平板电脑上工作(我不关心UI的外观)?或者它可以在某些设备/平板电脑上创建ResourceNotFound Exception,因为不存在所有可绘制的文件夹?