The problem here is caused by an unsuccessful combination of automatically scaling extracted resources in Android and very small drawings.
If, for example, your application provides drawable-xhpdi , they should be reduced to fit lower density screens. This is done automatically by Android, if you do not provide these resources yourself.
The display density scale is set as follows:
- xhdpi: 2.0
- hdpi: 1.5
- mdpi: 1.0
- ldpi: 0.75
This means that your xhdpi resources xhdpi reduced by a factor of 2.0 on medium-density displays. This can be detrimental to quality, so it is usually recommended that you create and provide these resources with lower density yourself.
Now back to the problem. It is not unusual to have a resource with a very small width or height (1 or 2 pixels). An example use case is to create a solid colored background for presentation.
Unfortunately, when providing these resources as xhdpi and reducing their size, the pixel size can be truncated to 0. There is no protection for this, and Android will not be able to create a bitmap with this measurement and crash.
There are several solutions for this:
- Include the resource as
ldpi , and instead it scales, which does not affect the appointment as a background. - Include the resource as
nodpi drawable and it will never scale. - Use an XML resource instead.
The latter option most accurately describes the intention and allows you to easily change color later without an image editing program:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#AARRGGBB" /> </shape>
Include this resource in the drawables folder and it will always work.
Overv
source share