Issue
I have a layout that has an image that needs to be displayed at different aspect ratio's depending on the screens size.
I tried to do it like this
app:layout_constraintDimensionRatio="@dimen/image_ratio"
And then specifying the different ratios in various dimens.xml files for the appropriate screen size.
<dimen name="image_ratio">3:1</dimen>
And I got it working exactly how I want it in the layout editor, but it won't compile.
Android resource compilation failed
Output: [...]/values-sw600dp-v13.xml:11: error: invalid dimen.
Not sure why it says the error is on line 11, as the problematic dimension is actually on line 58
I think its stupid that something that seems like it should work, and does work in the editor, doesn't work when it comes time to compile.
So how should I achieve this result?
Solution
Thanks to Jeel Vankede, I solved this. His proposed solution of providing the ratio from strings.xml would work, but would generate an extra set of strings.xml files for all the different screen sizes.
This is unnecessary, as you can store strings in your existing dimens.xml file.
I simply switched out the <dimen> tags for <string> tags, and then used @string/image_ratio instead in my layout file.
Answered By - lbenedetto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.