I'm creating a home screen for an Android app. The homescreen will be a vertically scrolling list, containing many different elements.
These elements can be things such as a simple card list, a side scrolling carousel of items (ViewPager?) or just a basic WebView.
Is it possible to use a RecyclerView efficiently with multiple types of content (that can also have their own adapters). Or is there something else available that I may not be aware of?
The BBC news app is similar close to what I am trying to do.
A RecyclerView is actually designed to do such things, I don't think that you have any other choices right here, however this shouldn't cause you any problems I've tried something like this earlier last month and it worked perfectly for me
even tho i added multiple types of content, the only problem that i faced was with the ListView because i added some sort of animation to the content
but after i used a recyclerView everything worked fine but you also have to reconsider using a ViewPager inside a RecyclerView as an Item, it might cause you some problems as it should be used in conjunction with Fragment to allow users to flip left and right through pages of data which in most of the cases are tabs.
checkout the documentation.
And the BBC news app that you refer to in your question is using a RecyclerView inside a tab into a TabHost that uses ViewPager.
More Information About RecyclerView.
Good Example for RecyclerView Sample for RecyclerView
Related
I'm the developer of Fulguris Web Browser and I'm faced with a weird issue in my tab list which is using a RecyclerView.
When scrolling fast through those tab lists, either horizontal or vertical ones, items get stuck mid-flight as shown on below screenshot:
That's hardly ever an issue when manually scrolling through the list. It mostly triggers when doing Ctrl+Tab which is using smoothScrollToPosition to move to the new current tab. It also seems to be more of an issue when under load like when loading web pages in the background.
Relevant source code can be found on GitHub.
That code base was using some custom ItemAnimator namely HorizontalItemAnimator and VerticalItemAnimator that were causing those issues. My understanding is that those classes were once parts of the AOSP, looks like they are long gone though.
Using DefaultItemAnimator which is obviously set by default on AndroidX RecyclerView fixes those issues.
I am trying to achive this:
First I tried by putting all my recyclerviews (with WRAP_CONTENT) inside a nestedscrollview. That worked, but the performance was awful. Then I tried to set a height for my recyclerviews, that was a lot better (especially the first gridlayout and the horizontal linearlayout loaded very fast), but still had the problem with the dynamic "category" part.
Now I am trying to put all my recyclerviews inside a single recyclerview with different viewtypes. Since that is a pretty big deal (I need to refactor a lot of code because I have diveded every area from the screenshot inside a single fragment and now I need to put all that code inside an adapter) I wanted to ask if I can actually expect any gain from this, because in the end its again a "nestedscrollview" (made by myself, but...). Or if there is some other "best practice" way to achive this layout.
Thank you
Edit:
As expected this didnt do the trick neither. When just the two first recyclerviews are added as viewtype it scrolls and loads smoothly. But as as soon as I try to add the category items (below the category), I notice a lag and especially when selecting multiple categories and scrolling fast up, there is noticable lag. I guess I will have to change my layout and move the category selection part inside a separate view, just need to come up with a user friendly solution. But its acutally quite dissapointing that, in my opinion such trivial task, laying out multiple tables, is such a pain in the ass on android.
I didn't manage to get it working with standard android stuff.
Now I am using epoxy from airbnb ,and I have converted all my views from nestedscrollview to the epoxy recyclerview. Its a great library, and airbnb use it too for all their views.
Nevertheless it's sad that the android dev team doesn't address this problem and provide a solution besides the info "don't nest multiple scrollviews(recyclerviews) that scroll into the same direction".
You can use Recyclerview in recyclerview.
https://irpdevelop.wordpress.com/2016/02/10/horizontal-recyclerview-inside-a-vertical-recyclerview/
And make sure to use multiple view types.
I am trying to implement a vertical listview with horizontal scroll on each item just like the facebook newsfeed. Suggested apps can be seen by scrolling to right and some part of next item is also visible.
here is the screenshot :
http://i.stack.imgur.com/7JRfM.png
So I am just stuck here and don't know how to proceed.
You're probably going to need to write some custom code (which is a pretty good rule of thumb whenever you're trying to do something Facebook did on Android; they do some crazy stuff).
I don't believe you can nest ListViews in Android. There is "ExpandableListView", which lets you expand items to show more, although this isn't quite the same thing.
I would advise to just create a vertical ListView, and have the items be horizontal LinearLayouts that you can inflate yourself. You can also try making them horizontal ScrollViews (although I think this may have the same limitation as using nested ListViews).
Good luck!
I'm trying to implement a sliding menu just like the one found in Google's Google+ Android app:
I've got the actual sliding menu working but I'm having trouble implementing a scrolling view that can hold any type of child views.
For example I would like to have a header like the "NOTIFICATIONS" row in screenshot and below it a ListView with notification items. And I would like to have another sections below that list, perhaps called "ERRORS" and below it a different ListView with errors. And perhaps a WebView at the very bottom.
How is this best implemented?
Note: I have read this tutorial but it's talking about a single ListView. I would like to construct this using a LinearLayout or alike, if that's possible.
The way I ended up implementing this was with a ScrollView that I simply populated with Views.
There are some things to be considered when using a ScrollView, like this answer or the Android documentation.
From what I understand, if you need a whole lot of items in a list then you should look at using a ListView. Otherwise a ScrollView will do just fine.
Suppose I have a list of data to be displayed. I know how to display it using a ListView And it is very simple and easy to do it that way. But I am looking for an alternative way to achieve the same. I don't expect to have more than 20 items in the data set I am planning for.
I was thinking of a number of squares that the user can swipe to see the next one etc, similar to some widgets on home screen.
I came across android.widget.StackView, any advice available for this?
You can try StackView (http://developer.android.com/reference/android/widget/StackView.html).
This is how the Gallery and Youtube widgets are rendered.
ListView is the best option for listing lots of data. It has very efficient loading property. But if you do not want it any specific reason, you have to use ScrollView and in ScrollView, you have to place a LinearLayout and in that LinearLayout, you have to place multiple LinearLayout(for each items of data).
Maybe you can use a ViewPager (available also for lower versions of SDK through compatibility pack).
http://developer.android.com/training/implementing-navigation/lateral.html - see also the project example top right of the page : EffectiveNavigation.zip
You can use a GridView, if you want to show multiple items on a page in a different fashion than in ListView.
You can also use ViewPager (from android 3.0, or with the support library) with your custom views.