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
Related
I have an Android fragment in which contains a Vertical LinearLayout with two layouts inside it: Another inner Vertical LinearLayout (which takes at least half of the screen) and a ListView (which shows a number of smaller Views). A good way to think about it is something like a facebook post along with several comments showing below it.
The problem I am facing is that the the inner LinearLayout is not scrollable and therefore parts of the ListView stays outside of the screen and there is no way to scroll the screen up to see the entire ListView (the inner layout could possibly take up the entire screen). Placing the entire layout inside a ScrollView is also known to be a bad practice.
I know one solution is to make the entire layout to be a ListView with the first cell to be the inner LinearLayout, followed by the cells from the original ListView. That however has its own issues: It is harder to recycle the views in the ListView, and generally I also see it as a bad practice where one cell has a different behavior from all other cells in the ListView.
Is there a better solution to this? I can imagine this is a typical problem and I hope to find a better solution than above.
This may help you:
ListView yourListView = new ListView(this);
yourListView.addHeader(getHeaderView());
You can also add footer to a ListView. When you do this, the header(or footer) will become part of the ListView, and so it will be scrollable. You can find the document here: http://developer.android.com/reference/android/widget/ListView.html.
Hello, I have a question,
Is there any possibility to skip the first scroll's that occur before gridView is loaded?
To get only those when user really scrolls my list?
I am loading more, and that scroll before any user action is messing up.
How are you loading the gridView?
If you load it using addView you probably won't have problem.
In my opinion the best solution is to create a scrollView that contains a LinearLayout (for example vertical), then add at this LinearLayout a list of LinearLayouts (horizontal), and every layout contained in list contains yours elements.
I have a LinearLayout with a nested listview which looks like this:
<LinearLayout ... >
<LinearLayout>
</LinearLayout>
<ListView>
</ListView>
</LinearLayout>
The problem is that the listview owns the scrollbar (so only content in the listview is scrollable) but i actually want the parent LinearLayout to own the scrollbar (so making the entire content scrollable).
Wrapping parent ListView in a ScrollView hasn't been successful because the ScrollView doesn't recognize ListView height (which looks like is rendered at running time)
Thanks
Edit: SOLVED My perfect solution was using a MergeAdapter, as advised by Barak
You can use CommonWares MergeAdapter which allows you to define views and list adapters, pour them into the MergeAdapter and get a single list adapter out, containing everything you poured in, and it scrolls as one list.
A previous answer about MergeAdapter I gave with some instructions is here
You could replace the Listview with a Tableview instead, as long as the listview does not have too many items in it. You can still use a childview with the tableview in much the same way as the listview, you just won't be able to databind it in the same way as you can with a listview, and the items won't recycle either.
Since the listview is designed to contain more items than can be displayed the height will never exceed the screen size (best case) which is the intent of the control, though I suppose you could force it to be larger that seems generally like a bad idea for a lot of reasons.
I suspect what you should do is either create a custom listview adapter, and based on position in the list create the view you want, this would allow all items to scroll like you want.
Listview with different view types per row
This may or may not work depending on what exactly you are trying to do, otherwise you might just want to add views to a linear view inside a scroll view san's the listview.
It just depends on the use case (how many items in the list view, memory issues etc) and what the purpose of the other views are.
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.
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?