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).
Related
I currently have an activity with a horizontal scrollview, and inside it I have an add button (ImageView) to let the user add some images to the same horizontal scrollview after clicking it. How can I display a group of images from app resources (such as drawable) as a sort of "pop up" to let the user pick one, without changing the current activity?
You need to create recyclerView with horizontal layout. The adapter of the recyclerView will have the functionality to implement a button click. The onClick of the button will add items to the adapter. These items may contain your required images.On every button click you need to call notifyDataSetChanged.
This can be solved by inflating a custom xml layout (containing a GridView) on an AlertDialog. To display the images on the GridView you need to create and set a custom adapter to it. The adapter shall have a function getView(), which will return each of the Views to be shown on Grid cells. You can also use Picasso Library to load the images.
Here is a brief tutorial
http://www.101apps.co.za/articles/gridview-tutorial-using-the-picasso-library.html
Hint: Remember to define the number of columns of the grid, and calculate the size of each image based on the screen size. This way you can fit the amount you like on each row. You can do this for both portrait and landscape orientations by overriding the function onConfigurationChanged.
Hint 2: Remember a GridView already has the scroll property, which needs to be activated (android:scrollbars="horizontal"). Using a ScrollView as parent of a GridView will cause it to wrap the image, even with MATCH_PARENT property activated, causing layout problems.
I understand the items that are visible to the user will be loaded when using GridView. Does this also applied when using GridLayout?
I currently working on laying out the applications' icon like the applications screen does. When user pressed the icon of the application they are allowed to arrange the icon in an unoccupied space.
At the moment, I don't know which widgets is preferred to use. If GridLayout behave the same as GridView, I would stick with that so no need to change the code.
If you want to be able to drag icons to rearrange them I would consider using GridLayout with RecyclerView. Take a look at Drag and Swipe with RecyclerView
Part Two: Handles, Grids, and Custom Animations.
If you are unfamiliar with RecyclerView and ItemTouchHelper then also look at Part One first
I have an activity which shows these three things in order.
ViewFlipper (User can fling it left/right)
EditText
ListView (List view can have n number of rows. lets limit it for 100. each row has images which get downloaded asynchronously)
I want that user can scroll vertically so I put above three item in single relative layout and that in to scrollView
<RelativeLayout>
<ScrollView>
<RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Problem with this approach
ListView and scroll view together is bad user-experience. When List will cover all screen user will have problem in scrolling complete view itself.
Solution which I could think of
Disable Scroll on ListView and let it show all items (Is this good enough)
User addHeaderView (not sure how to use it)
Second Approach (Which I did and ran into problems).
Instead of using ListView add LinearLayout (replacement of listrow) dynamically.
Problem with this approach
Lot of ugly coding as there is no sophisticated adapter for such scenarios. Need to populate each LinearLayout and it creates more issue because I have async Image loading for every LinearLayout.
What could be better approach. Any alternates?
Do not use a ScrollView and a ListView together, this is a bad thing as mentioned by Romain Guy, the creator of ListView. The problem with you LinearLayout approach is performance: you will need to create n new Views, while the ListView just reuses existing ones.
The solution I could think of (in case it is not possible to make your Layout components to fit on the screen without scrolling), you could disable scrolling in your ListView and add "scroll up" and "scroll down" buttons, setting the onClickListener and OnLongClickListener to let the user control scrolling speed. Though this might be not the best approach. Consider re-disigning your layout so the components fit on a single screen. This is usually not a good user expierince to enable scrolling because of layout components not fitting on a single screen. Your could add a page more to your ViewFlipper and place your ListView there for example
I need to make a scrollable row in ListView's item. The row should behave similar to Gallery or ViewPager. It was designed to behave similarly to Facebook gallery.
I was planning to use Gallery but since it has been deprecated I'm not sure if it's a good choice. Although Fragment is recommend to be used to replace Gallery, it's not expected to be put inside a ListView.
Is there other options for available? Or should I implement my own custom view to calculate and handle the view transition? Has anyone try something similar?
Make the row item a HorizontalScrollView with a LinearLayout inside.
Make the LinearLayout's oriantation horizontal and add the things you need inside.
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.