Horizontol Scrolling View in Android - android

I want to create a Horizontol Scrolling View in Android. The view would be a combination of images and text scrolling horizontally and I should be able to dynamically modify the content(text and images) in the Scroller
Any ideas?

add HorizontalScroolView in the scrollview it will scroll in both directions.
ScrollView
HorizontalScrollView
ImageView

You could perhaps also have a look at the Gallery element.

You'd like something like ListView, but in horizontal orientation.
I'd make this to extend AbsListView, which is made to display dynamic lists.
Ideally if you'd copy ListView source and switch it to horizontal mode, but this is very complicated and long class, so look for easier options.
Try using GridView with just one row, stored in a HorizontalScrollView. Feed it with a ListAdapter, provide Views for your cells and setup content to display.
I didn't try this, but it seems like easy solution. Assuming that number of items will not be large, because there won't be optimizations available in ListView class.

Related

How to implement a scrollView with more than one type of grid?

What I need is something like this:
If I use 2 gridViews, they will scroll separately. So I put 2 gridViews into a vertical LinearLayout, both gridViews have fillViewport set to true, and I put this LinearLayout inside a scrollView. But it doesn't work, the scrollView doesn't scroll to the full extent of the 2nd gridView.
I found this: Gridview height gets cut
Looks this can solve my problem by making the gridView grow its height, but as the comments say, this solution is not memory efficient, as it foregoes the cell recycling, and can cause crashes.
Is there any other better way to implement this?
Try ListView with custom items instead. Top grid may be set with setHeaderView method, and bottom grid should be replaced with a set of items to show. This is both default and memory effecient way, it loads only what you show and allows scrolling.

What is the best way to implement Header support in GridView?

Everyone knows that GridView does not supports headers and footers like a ListView.
There is a few ways to implementing this:
Use a ListView and form columnt manually via ViewGroups. It not works for me, because it's require a lot of layout operations like measuring and layouting, and it's difficult to implement draw selector on top.
Use special adapter. It works fine with a footer: we should fill last cells with a Space and manually insert after them out footer with width that equals GridView width. But this not works with headers: although header is stretched, next cells float on it.
Use a GridLayout. GridLayout is good, but what about performance with 500-1000 cells? AdapterView supports caching and reusing Views, as far as I know, this is not possible with GridLayout.
Extend GridView and write custom class, that allows to draw a header before the grid content. It's difficult, but it's should work very fast. Let's try to figure out how to do this:
Measure the header. It's very simple, I have not questions about this.
Layout header in the top of the grid. We also should consider with scrolling position to allow move header with whole grid content, so my first question is: how to know where bottom border should be located while scrolling?
Layout whole grid content after the header. How to do that? I've newer do this before.
Dispatch draw to the header view too and resolve overscrolling effect if it's not work well.
Handle the scroll event and refresh header position.
So what you can suggest me? How to do header offset? Is it right to invoke relayouting with every scroll event?
I searched an answer on a same situation with a GridView (but for a FooterView).
I've read attentively your suggestions and some from other websites. I had the same reflexion. I found a simple way as your tip: "Use special adapter. It works fine with a footer..." and this answer by #RaulSoto helped me a lot. But when I tried to update my gridview, I had a NPE, because my footer was not like the layout of my items and I had a custom filter which recalculated the getCount() method, but without understand that another view was added.
Finally, I found only solution which works: a custom class.
Create your own class as you said: "Extend GridView and write custom class" but don't extend GridView. You should extend with ListView and measure the entire width, the column width and the number of columns. I think, it's less difficult that to extend GridView, calculate the height of the header view and move it as you move your gridview or refresh the header each time you handle a scroll event..
I searched to do it in this way and I took this little project on GitHub: HFGridView by Sergey Burish. It was exactly what I need, no more.
I only added a custom attrs file in my app and customize a bit his project to have the expected result (especially, it was to have one column in portrait, two in landscape mode, refering to the numColumns attribute in my layout).
And when I try, just for test, to add a HeaderView and refresh the content with adding new items, the header view stays at the top of my gridview list, without refreshing himself.
So, I think you should search to create your class as GridView extends ListView. Refer you to the HFGridView by SBurish, it is very simple to understand how it does.
Hope this helps you with your purpose.

Is there a horizontal scroll widget inside listview

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.

Is it possible & efficient to put a LinearView and ExpandableListView inside a ScrollView

I'm making a GUI with two different parts. The first part (at the top) is composed of some banners, several fixed buttons. So I think using LinearLayout is the most straightforward way to implement. The second part is composed of several similar items grouped together which can be implemented by using ExpandableListView, I think.
However the problem is that the content exceeds the screen size. So I intend to put two of them into a ScrollView. I checked several sources, it seems that putting "ExpandableListView" inside a ScroolView is NOT possible, or not efficent, so I'm afraid...
Would you help to confirm if this is possible? efficient ?
If no, would you give me some recommendations for this layout design?
I'm indeed looking forward to your supports.
Sincerely.
If you have a fixed header at the top of a list, use ListView's header view feature.
Putting ListViews in ScrollViews fundamentally makes no sense and here is why:
ListView has one purpose: to efficiently display unbounded data sets. Since these can be extremely large (tens of thousands of items and more) you do not want to create a View for each item up front. Instead, ListView asks its Adapter for Views only for the items that currently fit in the ListView's measured space on screen. When an item's View is scrolled out of sight, ListView disconnects that View and hands it back to the adapter to fill out with new data and reuse to show other items. (This is the convertView parameter to an Adapter's getView method.)
ScrollView also has one purpose: to take a single child view and give it "infinite" vertical space to fit within. The user can then scroll up and down to see the full content.
Now given this, how many item Views would a ListView create for a 100,000 item Adapter if it had infinite height available to fill? :)
By putting a ListView inside a ScrollView you defeat ListView's key purpose. The parent ScrollView will give the ListView effectively infinite height to work with, but ListView wants to have a bounded height so that it can provide a limited window into a large data set.
Well Expandable List View itself has scrollable property by placing it in scroll view is really undesirable.As the both scroll would contradict and smooth scrolling can't be obtained in that case..
If we have any data to be shown prior or later to list...
Best way is to use header and footer view to list...
I recommend you use header and footer in your case.

Both way scrollable gridview in android

Is it possible to allow a griview to scroll both vertically and horizontally simultaneously in android? Please advise.
It doubt that would be possible. A GridView is based on an ArrayAdapter, having only 1 dimension for the items. How would you arrange them in a view that can be extended both vertically and horizontally?
Of course, if you just want to make it larger than the screen and use hard-coded number of rows/columns, you can put it in another scrollable view.
There are following two solutions and you can use one which fits your requirement.
You can use RecyclerView instead of GridView with a custom layout manager. You can read this code for help. Also, you can read this article on how to create custom layout manager. This article gives an example of how to create two-way scrolling grid layout.
The other solution is to use RecyclerView with horizontal scrolling Grid Layout wrapped inside a scroll view.
<ScrollView>
<RecyclerView />
</ScrollView>
use GridLayoutManager with horizontal scroll for recycler view.
The first solution is efficient in a way that it handles view recycling properly.
Hope this will help.

Categories

Resources