I'm using DashboardLayout provided by romannurik (https://gist.github.com/romannurik/882650)
This layout adapt children to fit on the screen and I want to implement a vertical scroll.
I want to keep the part to measure the max child per column but if children can't fit on the view I want to be able to scroll.
Can I have any leads to reach this goal ?
Dashboards have sort of become defunct. If you expect there will be enough items that you can need to be able to scroll, then maybe you should just use a GridView.
Related
I understand we always use listview to display list of items instead of Scrollview. But I know we can do it with scrollview also. I understand that performance of list view is better than ScrollView when you want to display list of items. My question is there are any reason for that also? And why nobody use scrollview to display list of items? Please give me your opinion. Thank you.
I often use Scrollview for displaying a limit of items, this number rarely be changed on runtime, such as in a configuration page. Otherwise, ListView is for display a lot of items. Those items may be the same type such as a list of Students, Messages, etc.
ListView uses a concept of dequeueing that is removing view from the view hierarchy when they are not visible. For example if you have 20 items and only 10 are visible at a time.
The listview will remove the top 1st element when 11th element comes
into view using scrolling. This reduces memory load and gives smoother
performance. Battery consumption is major factor of phone these days
and no one wants a app that consumes all the phone battery.
Scrollview on the other hand keeps all the view added in it in the view heirarchy all the time therefore increased memory usage and performance issues when the number of views added are huge.
ScrollView is used to put different or same child views or layouts and the all can be scrolled.
ListView is used to put same child view or layout as multiple items. All these items are also scrollable.
A scrollview on the other hand is quite different. You add other views to a scrollview which allows you to have more elements than what would fit on screen. Say, for example, you wanted to have 50 buttons or a large chunk of text. By using a listview you have a container that is the size of the screen but allows the user to scroll up and down to see the other views.
I searched for a few hours over the internet but I didn't find any example or documentation explaining how to create an horizontal list view with fixed number of elements.
Basically, I would like to have, let's say 3 elements out of n(total number of elements) which are displayed on the screen without taking into consideration the size of the scree. The elements can be bigger or smaller proportionate to the screen but the number of visible elements should be the same, fixed. see the image.
How can I do that? Any hint is appreciated! Thank you!
You can use TwoWayWiew third party library (i dont really recommend this solution), or if you want to avoid to use lib for this, just use RecyclerView, and you can set HORIZONTAL param to layout manager.
I would not use a ListView for this, but a RecyclerView instead. Performance is better in a RecyclerView and I honestly find them easier to work with. You can allow for horizonatal scrolling via the LayoutManager for your RecyclerView.
If don't mind scrolling horizontally by 3 items you could use a ViewPager with each View containing a LinearLayout (orientation horizontal) with three of your elements that have a
android:layout_width="0dp" and an
andriod:layout_weight="1"
for even distribution.
When you "scroll" you would just animate the next "page" into the screen bringing in the next 3 elements.
This might not be the most elegant solution but I think it would behave the way you want.
use the linear layout with its orientation set as horizontal under the relative layout
I have a listview with rows as big as the device screen and I want to show row per row while sliding, I don't want to show parts of rows when doing so, is there any way of doing it.
ListViews are not made for this kind of use case. ViewPagers are, but they scroll horizontally. It's possible to make it scroll vertically (see Android: Vertical ViewPager), which should be what you're looking for.
The problem with adjusting the size of each ListView item to fill the screen is that match_parent simply doesn't work. You would need to calculate the exact size you need (screen height minus action bar and other views that are not part of the ListView). It's probably possible, but not worth the trouble.
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?