Custom view on different screen sizes
I have a custom view, the DateView
(which extends a LinearLayout
) which when given a date, presents it. The issue is with the sizes of the screens, I want the DateView
to present the date differently on the small, normal, large an开发者_开发知识库d xlarge screens. The DateView
extending a LinearLayout
is useful because I can instantiate a DateView
and addChild
at any point.
Any ideas?
Wow! Ran into this age-old question that I asked. Anyways, this is how I solved the issue.
There are two ways (that I have come to like) to address this issue
- Create multiple layouts for multiple screen sizes. At runtime, load the layout into the DateView, which is (something like) a FrameLayout. Find the views from the layout and populate content.
- Use the Java Delegation pattern: Create multiple layouts for multiple screen sizes.
include
the pattern in client XML layouts. In the client classes, load theinclude
ded layout and pass it to a DateViewManager class which exposes content modification methods.
I've come to prefer the second method for it's cleaner and simpler way of achieving the goal: use the Android resource management capabilities to provide for multiple screen types.
精彩评论