Search code examples
androidandroid-widgetgesture

Are Android app widgets (for home screen) allowed gestures?


I noticed that when I swipe my finger from left to right across a home screen widget, in simulator on a AVD, Android switch to the left home screen.

I was wondering if its possible to prevent this behavior and allow home screen gadgets to listen and react to finger gestures (like swipe)? Its very critical for my widget UI design.


Solution

  • Starting with API level 11 (Android 3.0.x) you can use "android.widget.RemoteViewsService.RemoteViewsFactory" and and assign a widget to use (from docs):

    ListView: A view that shows items in a vertically scrolling list. For an example, see the Gmail app widget.

    GridView: A view that shows items in two-dimensional scrolling grid. For an example, see the Bookmarks app widget.

    StackView: A stacked card view (kind of like a rolodex), where the user can flick the front card up/down to see the previous/next card, respectively. Examples include the YouTube and Books app widgets.

    See http://developer.android.com/guide/topics/appwidgets/index.html section Using App Widgets with Collections.

    So yes - if you use one of the above layouts your widget will accept gestures.