I've got a question regarding list views in Android. I want to create an activity that can display lots of information. I want to display each player horizontally (there could be anywhere from 2 to 256 players, but most likely there will be like 8) and there will be 10 - 20 rows under each player.
Is there a way to create a ListView that can scroll both directions? If not, what is the correct design approach to handle this type of problem?
I've tried to look into this a bit, and a GridView won't work because there will be items hanging off the screen; they won't all fit in the grid.
Thanks!
-Justin
Use a ViewPager instead so that the user can scroll through the player in the horizontal way that you want.
This way each player will be in a fragment, and the fragment can contain a vertical list that will show the rows that you require.
The benefit of this is that the viewpager can handle a huge number of players and rows for each player without impacting memory performance and in a less cramped space.
You can try using an ExpandableListView or a ViewPager.
Related
In my project I have an Activity that loads a list of news. When the list is loaded, this Activity is populated with the information of the first item on the list:
But since this loads all the news from the server, I want the user to be able to swap the news with his finger. For example: we start with news[0] and user swipe left, the content change to news[1]. The user swipe left again and the content changes to news[2] and so on... if the user swipes right, then it return to the previous news (news[1]). The header should not have a swipe movement, only the main frame (image and body should change):
What would be the best aproach for this behavior? I was thinking about using a TabLayout with ViewPager but I'm not sure if this is the correct way to do this. If I have something like 100 news this could be a overkill to load 100 fragments in the ViewPager right?
Does android have a better way to do this? How should I do this?
You can use ViewPager for that. Having 100 fragments inside is totally fine because ViewPager will only load as much as you set using setOffscreenPageLimit(pageLimit). For instance, if you set pageLimit = 3, ViewPager will only initialize 3 (up to 6) neighbour fragments that are on the right/left side of your currently visible fragment. And while you're swiping through fragments, it will kill the fragments that are out of this limit, and load new ones. So, there will be no overkill.
So I have a question about best practice for dynamically creating and sizing buttons within a ViewPager, based on a changing external state.
Essentially, I have a scrolling view and I want my ViewPager to contain a number of buttons of a specific size and count depending on what part of the scrolling view is currently visible.
My question is about deciding the best implementation of this feature, I see two options: would it be simpler to
Constantly create and scale new buttons whenever the scrolling view moves
Make the viewpager itself contain a scrollview and fill it with all of the pre-scaled buttons on app startup. Then, whenever the user scrolls the main scrollview the viewpager's scrollview (which contains the buttons) will scale programatically
Any ideas on which would be the simpler and more robust system?
Not much of an answer but I will leave a comment for ya! Basically you can do it either way, both aren't to difficult to accomplish, however I would probably go the dynamic route because it will always scale correctly. Doing a set amount will only work until devices become larger, or if you are targeting tablets or tvs then it will start to become extremely messy in the xml file for the layout. Dynamically adding also gives you far more control and saves time later on, you can simply change a number and have 100 more then going through and manually adding even 10. Hope this helps!
I have to create a listview inside a fragment that should always display the first 3 items no matter what screen size (rest should be scrollable). These 3 items should fill up the whole available space, which means that the item height has to be adjusted dynamically. You could also say: The first three items should take up about 33% of the listview each.
Is there a way achieving this using LinearLayout and layout weights? If not, what would be the best way to to this programatically, e.g. by determining current fragment size or something like that?
I managed to get the height and width using OnGlobalLayoutListener.
After all, we decided this wasn't a good idea layout-wise, but I thought someone might find this interesting nevertheless ;)
Try using the view.setMinimumHeight(int) on the inflated layout in your list adapter and supply it with a desired height.
As for obtaining screen size you can check this SO post
Edit: Apply that method to the layout that defines each item. You need a custom adapter and do that work in your getView method
You could probably calculate the size on the fly by determining the screen size, and adjusting the height of the list items as they are created & added to the list. This question and this one might help shed also shed some light on using weights, and would clean up your code.
I'm trying to create a basic UI for a simple Temperature Conversion app (new to android developing), and I can't figure out how to create a SINGLE page with two SEPARATE scrollable view pagers, one occupying the top half and the other occupying the bottom one.
I am using Eclipse. Feel free to ask for any other information required for your answer.
This is a rough drawing of what the layout should look like.
I'm trying to create a basic UI for a simple Temperature Conversion app
I do not know why a temperature conversion app would need one ViewPager, let alone two in the same activity at the same time.
I can't figure out how to create a SINGLE page with two SEPARATE scrollable view pagers, one occupying the top half and the other occupying the bottom one
In terms of the ViewPagers themselves, use a LinearLayout or something to vertically stack them.
Your bigger headache will come with the PagerAdapter implementations. At least one of these will have to be something other than FragmentPagerAdapter or FragmentStatePagerAdapter. Those implementations assume that they are the only such adapter for your activity, and I would expect that having two will cause collisions.
I'm working on an android application and I have run into a decision that I can't decide on one way or another. I was hoping someone could shed some light on the common practices and any theory to back them.
Here's the issue:
I want to have a list of items with images and text like table...
Country -.-.-.-.-.-.- Pop -.- SqrMi
[img] US -.-.-.-.-.-.- xxx -.-.- xxxxx
Now the debate I'm having is whether or not to use a listview to display the data or instead nest a layout that is scrollable and just display the data that way.
Why would I even consider a nested layout? Flexibility. I can design the dividers, possibly throw in a couple graphs above/below the list. Vary the height of each of the list items (like what if I want to show a graph in one list item and no graph in the next), etc.
I'm not sure if I'm breaking the generally accepted methods here. Can anyone shed some light on this?
The only major problem you will have when using nested layouts is memory consumption. ListView reuses its children so it doesn't create more children then it can display at a single moment. This description is a little simplified but I hope it shows the purpose of the ListView. Also ListView implements its own fast scrolling so it doesn't have to measure all its children to determine its size. And ListViews use adapters to populate themselves with data. It's a nice and convenient way to obtain data.
On the other hand if you create a ScrollView with a lot of views inside it'll be slow, difficult to populate with data and it'll require a lot of memory to create all of the child views even if you don't ever see some of them.
And about flexibility of the ListView. You can store different types of view in a single ListView and you'll be able to vary the height of each of this views.
All the things you have described for your "nested layout" is achievable with ListView. Just use different types of rows, use headers/footers in adapter.
And as already Pixie said, ListView is much more memory efficient and faster.