Android Custom Layout
Solution 1:
I think that Android Layout are great for most use cases for interacting with users, BUT (a big But) the Layout mechanism is very delicate and is tricky to extend correctly. For small tweeks it's fine, but if you want to do something out of the ordinary (such as an animated carousel), you probably do free graphics anyway, so you don't need the extra complexity of extending Layout. It's just more constraints to live with, with no justifiable added value.
Most apps have some standard stuff (ActionBar, buttons, preferences, dialogs, etc), and one or more "unique" elements. So my suggestion is to use standard layout for the standard stuff, but for your unique elements use one of these:
1) SurfaceView - very easy to use. See the official Lunar Lander code example. To see SurfaceView in action, you can also take a look at my app video, which uses SurfaceView for the animated element, and everything is laid out with RelativeLayout.
2) opengl - It's the most powerful way to do graphics on Android. It runs on the GPU, so CPU can be free to do other things. And it's 3D (or 2D, if you just use one plane). I'm using libgdx, and it's great, and not difficult after a short learning.
Both SurfaceView and opengl (GLSurfaceView) are views, so they can be added to a layout as any other view
Solution 2:
This is a FANTASTIC question. I am programming for 3.0 and above currently, and have decided for the most part to stick with AbsoluteLayouts in many cases. While it is set to be deprecated, compiling for 3.0ish and below most likely will still be able to run on 4 and beyond systems for a bit. Im searching for this answer myself (for future versions of the OS that cut it out). The reason they are cutting it out is because of there being no standardization of screen resolution on Android.
My suggestion would be to use AbsoluteLayouts for AS LONG AS WE CAN. I also think we should start a push to let Google know that it is still a Very necessary API to their platform.
Great Question :-)
Solution 3:
There is a nice example in: http://www.google.com/events/io/2009/sessions/TurboChargeUiAndroidFast.html
Minute 44
And even better at: http://www.google.com/events/io/2009/sessions/SupportingMultipleDevicesBinary.html
Solution 4:
The available documentation on custom layouts seems rather vague to me, but I finally found something useful: Here is a nice simple sample layout that shows how to connect XML and Java code: How to layout a 'grid' of images in the center of the screen And here is a post which explains one key issue I was missing: http://www.arpitonline.com/blog/2012/07/01/creating-custom-layouts-for-android/. Apparently one has to override onMeasure and call measure() for each child.
Post a Comment for "Android Custom Layout"