I use xhdpi
resources in my app and let the system scale them to other dpi
s.
Among the other resources I have 1px wide png file as stretch background for a view.
The problem is that I received some crush reports from ldpi
device users (like Galaxy Pocket) with the error like
Caused by: java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:603)
at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:649)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:624)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:476)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:775)
at android.content.res.Resources.loadDrawable(Resources.java:1974)
... 34 more
As I understand, my 1px wide png is causing this problem. 1 px in xhdpi
is scaled to 0.375 px in ldpi
, which I think is rounded to 0px. Currently I have just increased width of my resource to 5px, and tested on Galaxy Pocket, and it worked for now. But I would like to sort it out completely with your help. Is my guess correct?
The xml where I use it:
<LinearLayout
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ui_topbar_bg"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingRight="8dp">
@drawable/ui_topbar_bg
is the image name