I am building a library of reusable components. These components are all custom Views (not Fragment or Activity). I have different layout files for each of these components to work best in portrait (view height > view width) and landscape (view width > view height). This works great when one of the components takes up the whole screen.
However, sometimes I will build an app that has several of these components on screen at the same time, for example:
In this case, even thought the device is in landscape orientation, since the custom Views are each taller than they are wide, they should be using the portrait resources (layouts, dimensions, etc.).
I have a similar situation in portrait orientation:
Here it is clear that each View is wider than it is tall, so the View should be using the landscape resources instead of the portrait ones.
Even though this is basically a simple example of "responsive design", I have not found any easy/reasonable way to deal with this issue and am looking for clever solutions. Things to note before you write an answer/comment:
- These components are
Views, they must remainViews. The are notFragmentorActivity. - I do not intend to change the size of the
Viewonce it is placed on-screen. TheViewdoes not need true "responsive design" capabilities (ie: it must not resize dynamically or anything like that). - I have read this discussion about using window size classes and it does not help me because that is only relevant to the window hosting the App itself. In my case, I need a solution per
View. - I do not want to force the device into either portrait or landscape mode. The user can switch between portrait and landscape mode and each
Viewwill be recreated, but it must use the appropriate resources based on the size of theView.
Any brilliant ideas?
from Force the use of landscape resources for a custom VIEW with device in portrait orientation


No comments:
Post a Comment