Two-way scolling list view? - android

I'm researching creating a view for displaying EPG data. That is the view should:
have a fixed header column that shows the services,
have a fixed header row that shows the time and
a content area that has equal-height TextViews of flexible width for showing the actual EPG entries
Most importantly, scolling vertically must scroll header column as well, scrolling horizontally must scroll header row.
Apart from drawing the whole view myself (inside a scrollable?) I'm totally stumped if there is any good approach I could use involving linear layouts or such.
Any hints are greatly appreciated- please note that I'm and android beginner.

Approach 1: Everything (that is all views) are pre-generated.
Have top and left one-way ScrollViews together with a bidirectional ScrollView and have the scolling be synchronized ( Android: Synchronized scrolling of two different views ). Synchronized scrolling isn't to difficult to do if you've subclassing the ScrollViews and add your own ScrollManager to handle notifications.
Drawback: ScrollViews inside ScrollViews for the main content area do seem to be the desired option. The whole thing will become highly resource intensive as all items need to be created upfront to be available for scrolling.

Approach 1 takes care of view-synchronization for the scrolling, but is a huge resource hog (imagine an EPG with 30+ channels and 100+ events per channel).
Approach 2
One approach for this I could imagine would be- for the main content area- a ListView with a custom ArrayAdapter. Custom adapter would probably return a LinearLayout or similar holding the individual events. That way, scrolling would still work bidirectionally if the ListView is put into horizontal ScrollView and at least the LinearLayouts themselves could be recycled by the ListView.
Are there better approaches?

Related

Overwhelmed by layouts, what are my alternatives to make a layout like this, but dynamic number of items?

I'm a flutter user trying out kotlin dev first time, but im kinda confused what the best alternatives for this type of layouts are.
I understand that I use recyclerview for a dynamic number of items. And since theres two dynamic ones (one for number of sets, one for each exercise). Do I use two nested recyclerviews?
It really depends what you're doing here. A RecyclerView is basically a list, so it's a good choice for a scrollable set of items - which it looks like your Exercises are. But how do you want to display those weights?
It's possible to make them scrollable, so some of them aren't visible on the screen (the categories on the Play Store act like this). For that you would need a nested scrolling view of some kind - could be a horizontal RecyclerView, or it could just be a ScrollView wrapped around a LinearLayout you throw views into.
But the other option you might want, is that for each Exercise, all of its weights are visible in a grid of some kind. No scrolling, all there up-front to see and poke at. So the first question is which of those do you want?
I'd assume it's this version - where you can easily visualise the contents - in which case you're not talking about nested lists, it's just one list, and each item contains a grid you can add things too. For that setup, there's GridLayout, TableLayout, and ConstraintLayout Flow (which acts like FlexBox if you're familiar with that). So in the layout for an item in your list, you have a container for stuff, and you put the stuff in it, and the container expands vertically as needed

When to use a Scroll View in Android?

My question is about best practices in Android in terms of using ScrollView to scroll other views and widgets. This is to know when to use a ScrollView to eliminate redundancy of scrolling if scrolling is possible in a given widget/view/layouts.
So I notice that there are instances where I don't really need to use ScrollView to make things scrollable. Few of the widgets/views/layouts that I know of are TextView and ListView. This is supported according to this documentation.
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
The TextView class also takes care of its own scrolling, so does not require a ScrollView, but using the two together is possible to achieve the effect of a text view within a larger container.
My question is, are there other widgets/views/layouts that handles their own scrolling other than the two I have stated above and the documentation has. Maybe there are others that are scrollable or other methods to make things scrollable other than the default of some widgets and by using the ScrollView.
Preferred answers must be base on experience and documentation (other than what I've shown). Thanks in advance for any good answers.
WebView is one other class that does its own scrolling. My "best practice" advice is to use ScrollView to add scrolling to an arrangement (usually vertical) of fixed-size widgets. As you have noted, variable-sized widgets such as ListView provide their own scrolling.
if you read the official documentation you will find that tell you when not to use ScrollView:
You should never use a ScrollView with a ListView, ListView Because Takes Care of Its Own Vertical scrolling. Most importantly, doing all of the defeats esta Important optimizations in ListView for dealing with large lists, since it forces the ListView Effectively to displays its Entire list of items to fill up the container supplied by ScrollView infinite.
More information here.

What should be design approach - ListView Vs LinearLayout

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

Creating a large ListView with custom complex child Views

I have an unusual project that I need to display large sets of questions to the user. Given the amount of questions that will be shown on the screen and accessible by the user I have opted to using a ListView. I tried a ScrollView, but it wasn't as efficient as I wanted, and lagged when dynamically adding new sets of questions.
The basic structure will be a ListView whose children are custom Views that I have created that have LinearLayouts inside that expand and collapse based on a button in each custom view. The LinearLayouts will hold the question's widgets, TextViews, Buttons, EditTexts, etc. In each collapsible view there will be at least 20 widgets. There will be many custom views in the ListView. One problem I had was scrolling of the ListView when showing that many widgets. It worked OK when the custom views were collapsed, but when a bunch were expanded it lagged the scroll.
Is there a more efficient way of displaying huge amounts of widgets than enclosing them in a ListView? I thought ListView might be my best bet because it recycles the Views.
This is a very unusual project, as the questions inside the ListView will change dramatically based on certain information entered by the user.
For having this kind of list is better to use the ExpandableListView
It have a better performance but you only draw one item expaned.

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.

Categories

Resources