Can anyone tell me what views can I use in an appWidget?
Thank you!
according to the official android API:
A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
FrameLayout
LinearLayout
RelativeLayout
GridLayout
And the following widget classes:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper
Descendants of these classes are not supported.
RemoteViews also supports ViewStub, which is an invisible, zero-sized View you can use to lazily inflate layout resources at runtime.
Also starting with android 3.0 the next views are supported:
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.
AdapterViewFlipper - An adapter-backed simple ViewAnimator that animates between two or more views. Only one child is shown at a time.
See the app widgets article on the Android Developers' site for a list of the layouts and views available for use in a widget.
This list provided by Christopher is technically correct, but it is not quite complete. Although these layouts and views are available, many (most?) of the presentation methods cannot be invoked. For example, if you try to programmatically change the background color of one of the supported widgets (TextView), you will receive a runtime error:
WARN/AppWidgetHostView(606): android.widget.RemoteViews$ActionException: view: android.widget.TextView can't use method with RemoteViews: setBackgroundColor(int)
I've yet to see a definitive list of what is and is not supported. The android-dev list has seen a few threads (one, two) on the topic, but not much more. The work-arounds are not so great.
Related
I have been developing android for a while and I have been facing many similar layouts to the one in screenshot (in both iOS and Android)
So what I would like to achieve is the different number of childs in each row.
Well, first I would like to ask is there a specific name for this layout type, it is not gridview although very close to it.
The structure seems like it can be populated with an adapter since all child buttons look alike
Any help, suggestion, solution or example library is much appreciated.
Taken from Foursquare for Android
Since there is a chance of more than two childs (as you said) therefore what i think is that you can't accommodate so many childs as they would not be visible unless the listview row is horizontally scrollable.......I think you can use gallery widget as an item of listview and then you can have different childs in each row... You can google about the gallery widget, instead of images add your custom layout as gallery item.
I read this here:
Android provides a number of ready-made views that you can use to
design and organize your layout. "Widgets" are views that provide a
visual (and interactive) elements for the screen, such as a button,
text field, checkbox, or just an image. "Layouts" are views derived
from ViewGroup that provide a unique layout model for its child views,
such as a linear layout, a grid layout, or relative layout. You can
also subclass the View and ViewGroup classes (or existing subclasses)
to create your own widgets and layouts and apply them to your activity
layout.
If I am not wrong, this means people can even design their own widgets and layouts? Does that ever happen? Any examples?
this means people can even design their own widgets and layouts?
Yes.
Does that ever happen?
Yes.
Any examples?
There are hundreds of examples out on the Android Arsenal alone. Just looking at a couple of columns of the recent items, there are the following custom widgets and containers:
material-drawer
Material Design Android Library
StarBar
AndroidProgressLayout
DiscreteSeekBar
Android-SingleInputForm
SunDate Picker
I'm trying to achieve something similar to this:
So, this is a container which can hold an arbitrary number of children. Each child is a simple text with border. Children may differ by their width. I assume this part can be implemented by extending the TextView widget (since it isn't clickable). Much more interesting thing here is the container for these bordered text views. It should support a regular addView(child) operation which automatically aligns the child according to the simple rule: if there is enough room within a current row - place child to the right of the last item in row. If there is no space - move child to the next row. So the basic logic seems quite similar to TextView or EditText: if text is too long, we display it in several lines. My idea is too extend RelativeLayout, but I still hope to find something easier.
The scheme I've described above (custom container + custom TextView) is not a mandatory, I'm just looking for ways to achieve this. Any thoughts guys?
Seems that pattern I was looking for is called FlowLayout (thanks to nitzanj). There are several of implementations of it:
FlowLayout by blazsolar
FlowLayout by ApmeM
If you decide to write your own version, here are helpful guides about writing custom views:
Official docs
Dive into Android (video)
Custom views (video, Google I/O 2013)
I am new to android therefore I got a little bit lost with all those ViewFlipper, ViewSwitcher, ViewAnimator and ViewPager. Moreover, I am not sure what's happening under the hood.
Basically I have an activity which shows some data. With swipe (or button, doesnt matter) I would like to scroll the view and get to another page (as seen in the picture below).
Is it possible to implement something like that without changing to another activity?
I am a little bit confused regarding views and access to the design elements. How those pages are located each to another? e.g. If I am currently seeing Page1, can I modify content of Page3? Or plainly saying, are all page views loaded all together? As if I set setContentView(R.layout.xlayout); then I can access only xlayout elements.
But if I use same activity, then I have a thread there which updates a counter on Page1, if I change view to Page 2, the counter will not find Page1 Counter TextView and will complain.
As I Understand Android 4.0 has ViewPager which is similar to the seen in the picture. I am using GB. Should I use support library or can I just go around and implement something similar without importing any libraries?
(Sorry, my description is a little bit messy)
Yes, you can use ViewSwitcher, ViewFlipper and ImageSwitcher depending on your requirements.
ViewSwitcher may have two childs at max. And these child might be a View or an object of subclass of view.
ViewFlipper: May have as many childs you want. and these child might be a View or an object of subclass of view.
ImageSwitcher might be used to switch images over.
By using view flipper you can display one item at a time, and adding a gesture overlay, you can apply sliding effect. To apply View Flipper, you need to add all the views to ViewFlipper, and showNext and showPrevious methods are used to show next and previous child.
You need to use a ViewPager to have the same behaviour as in Google Play.
it only available on recent version of Android, but you can use the Compatibility Package to make it available for older version.
With a ViewFlipper you can't "scroll" between two pages.
I have a list of items loaded.
What i want to do with the items is load them into a list in a widget.
But i know list widgets are only supported on 3.0 and above.
So what would be the work-around to get this done?
EDIT:
Maybe add a textview each time a item is loaded...and load the text views into a scrollview?
There is no way to support scrolling on a stock home screen before 3.0. Widgets use the RemoteViews framework, which on Android 2.x only supports AbsoluteLayout, AnalogClock, Button, Chronometer, FrameLayout, ImageButton, ImageView, LinearLayout, ProgressBar, RelativeLayout, TextView, and ViewFlipper. The only way you could make something at all list-like, is to have up and down buttons for scrolling between items (note: this could only work for complete clicks--you couldn't have it scroll while holding down the button, for example).