The issue you're facing with the
layer-list item size not working on Android API versions lower than 23 is likely due to a known bug that affects
layer-list items on older Android versions.
layer-list in Android, the
item elements inside it should support size attributes like
android:height. However, on API versions lower than 23, these attributes might not work as expected, and the size of the
item might be ignored or not rendered correctly.
Unfortunately, there is no straightforward fix for this bug on older Android versions. As a workaround, you can try alternative methods to achieve the desired appearance:
Using Vector Drawables: If possible, consider using vector drawables instead of
layer-listfor your drawable resources. Vector drawables are well-supported across different Android versions and can scale without loss of quality.
Using Individual Drawable Resources: If you have simple shapes or images, you can create individual drawable resources (e.g., PNG files) for each layer and stack them using
layer-list. While this approach might require more drawable resources, it can provide better control over sizing on older Android versions.
Using Different Layouts: Depending on your use case, you can use different layout files or layouts with different dimensions for specific API versions. This way, you can customize the size and appearance of the elements based on the Android version.
Using 9-Patch Images: For certain cases, you can use 9-patch images to define stretchable areas within your drawable resources. This might help you achieve the desired appearance on various screen sizes and densities.
Using Compatibility Libraries: There are some compatibility libraries or support libraries that aim to address issues with older Android versions. You can explore these libraries to see if they provide any solutions for
When deciding on the approach, consider the complexity of your drawable resources, the specific use case, and the trade-offs between different solutions. It's also essential to test your drawable resources on different Android versions and screen densities to ensure they work as expected.
Keep in mind that Android API versions lower than 23 have limited support, and if possible, you should consider targeting newer API versions to benefit from the latest features, bug fixes, and improvements.