Search code examples
androidandroid-appwidgetflowlayout

FlowLayout for Android Widgets


Romain Guy created a great presentation and sample implementation for a FlowLayout in Android Activities (which he links to in the answer to this question: How can I do something like a FlowLayout in Android? )

I would love to use something like this in an App Widget but they seem to be extremely locked down to the layout classes mentioned in the documentation: http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout .

I tried to extend LinearLayout but it appears descendants of the mentioned layouts are not permitted. Perhaps I can programatically rearrange my TextViews using a RelativeLayout?

Is there a smarter way to achieve this?

Why are Widget layouts so very restrictive? Am I missing something important?


Solution

  • I tried to extend LinearLayout but it appears descendants of the mentioned layouts are not permitted.

    Correct.

    Perhaps I can programatically rearrange my TextViews using a RelativeLayout?

    I don't see how, as you are not the one rendering your UI.

    Is there a smarter way to achieve this?

    It is unclear what "this" is. If "this" is "a FlowLayout type UI for an app widget", either write your own home screen (so you can have the UI you want without the need for an app widget), or redesign the UI. App widgets have a limited palette of available widgets and containers, as you have noted.

    Strategically, you could contribute a FlowLayout to AOSP and home that it becomes available in some future version of Android, and further hope that it will be enabled for use by app widgets.

    Why are Widget layouts so very restrictive? Am I missing something important?

    App widgets are rendered by the home screen. There are thousands of home screen implementations. They run in their own processes, with their own code, written by their own developers.

    As such, you are not actually creating widgets in your app that are displayed by the home screen. Instead, you are creating a data structure, describing the widgets you want the home screen to create on your behalf. As such, RemoteViews does not support app-defined subclasses, simply because your app's classes are not in the home screen's process.