I'm on a research to design a ListView with horizontal scroll of views - something like in the facebook app.
I also need to implement a caching for the horizontally scrollable views.
Some of the options I can think of are:
Horizontal scroll view items.
A ViewPager which I understand is not quite good for this task.
What would be my way to go on this?
I've read some StackOverflow questions and am still researching but none of what I read so far also implement caching for the scrolled horizontal views.
Just use two RecyclerViews which are nested. The backing data is a two dimensional array as the layout is two-dimensional. The outer RecyclerView passes the data for the inner RecyclerView when the onBindViewHolder of the adapter is called. Additionally you may also use different layouts or ViewHolder respectively if the inner view consists only of a single item and does not require horizontal scrolling.
Some references about implementing RecyclerViews
Here: http://www.bignerdranch.com/blog/recyclerview-part-1-fundamentals-for-listview-experts/
Here: https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html
and here: https://developer.android.com/training/material/lists-cards.html
This will help you. You can use caching while scrolling. For example if you load images with horizontal scroll bar, you could use picasso library for catching and loading images.
Dont think big we have some library that will do what you want below listed some of them
https://github.com/sephiroth74/HorizontalVariableListView
https://github.com/EmirWeb/parchment
https://github.com/MeetMe/Android-HorizontalListView
any one this link will help you i belive
https://guides.codepath.com/android/Implementing-a-Horizontal-ListView-Guide
https://www.airpair.com/android/horizontal-image-galleries-android-studio
Related
I have two RecyclerView inside the NestedScrollView and I need track viewed items of my RecyclerViews. But problem that using nestedScrollView the recycler pattern doesn’t work and all the views will be loaded at once because wrap_content needs the height of complete RecyclerView so it will draw all child Views at once.
Is there any way to track of the viewed items with this approach? Please help me.
never use RecyclerView inside NestedScrollView because your ViewHolders will not be recycled and you will be in danger of OutOfMemoeryExceptions, it may work for lists with small sizes but as the list size increases it becomes worse,
instead of using one ScrollView and 2 RecyclerView as child
you have to completely remove ScrollView and instead of that, use one RecyclerView with multitype ViewHolders, in other words you need to combine those 2 RecyclerView in on RecyclerView .
To achieving this you can combine those adapters manually or you can use ConcatAdapter that depends on what you want, this link may also help you if you want to use ConcatAdapter but that is not necessary.
then you can have different approaches to track the visibility of viewHolders like layoutManager.findFirstVisibleItemPosition() and etc.
I know this topic has been 'touched' alot of times, but I still haven't found the correct way of implementing recyclerview/s inside recyclerview.
My goal is to have a single vertical recyclerview as parent and multiple horizontal recyclerviews inside of it.
I found an implementation to this within this post answer:
How do I layout nested RecyclerViews, while remaining performant?
What it suggests is, inside parent recyclerview onBindVH() method call
holder.setAdapter(childAdapter).
Is this correct way? I think, this is not the best solution performance wise. Is there better solution to implement nested recyclerviews (explanations are welcome)?
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.
My assignment is to create an interface much same like Google Play Store.There will a Category name followed by 3 or 4 cards (horizontal) followed by More button. Then again next category.
I already had implemented this using nesting the horizontal listview inside Vertical listview.
I know, I can achieve this by using the Recycler view with LinearLayoutManager with horizontal orientation. Using this I'll be having one only row.
My question is how do I add 2nd, 3rd row to this?
Should I use again nested Recycler view?
Are there some better options?
Dont use nested listviews (you cant scroll horizontally in play store).
Consider the following options:
You can use a simple LinearLayoutManager and make different view types. For the with 3 cards horizontally use a GridLayout or LinearLayout with same weights. The problem here is, that you have to consider the indexes of your underlying data list used in the adapter
Write your own LayoutManager for RecyclerView
Use TwoWay View which is based on RecyclerView and offers a Spannable Grid Layout manager, which seems to be what you are looking for.
If you inspect the layout of the Google Play app, they do not use a listview/recyclerview for the horizontal cards. I'm pretty sure that is just a linearlayout (horizontal) within a vertical listview / recyclerview.
If you insist on using a horizontal recyclerview for each row, then having a nested recyclerview would be your best option. You can specify a RecycledViewPool so that all the nested recyclerviews share the same pool instead of creating their own.
You may like to do it as one vertical RecyclerView (Main recycler) and for every section you can inflate a horizontal RecyclerView as well (Section recycler) as this blog answer mention:
Also, consider using:
A cache layer for Bitmaps for persistent access through your other store screens
A lazy load method for your category/section images
A place holder before showing new items
I have a list view in which I want each list item will contain images. But the images will be displayed one at a time. SO, at a time for every list item only one image will be displayed. To view other images in the list item,one has to swipe horizontally. Is there any inbuilt widget that handles this in android?
EDIT1
My List item not only has Image but it also contains other views like textview, seekbar etc. So each list item will contain Image, textview, seekbar etc but the majority of the space will be occupied by the Image. Now, for each list item, when the image is swiped horizontally, another image has to be downloaded from a ulr and displayed.
EDIT2
I did a bit of research on ViewPager but many references like the answers here and this blog seem to suggest that using ViewPager inside a listview is not a good idea. Why is that? If it is not a good idea, what is a good alternative?
This problem can be solved by using ViewPager.
Link: http://developer.android.com/training/animation/screen-slide.html
ViewPager(for swiping between views) + UniversalImageLoader(for loading images from URLs, with caching etc)
If it is not, what is a good alternative?
I think you should use RecyclerView with LinearLayoutManager.HORIZONTAL. All things like recycling the views, view holder design pattern can be done easily with it and it is a new widget that google introduced and you can use it instead of ListView + ViewPager. because as you suggested it is not recommended to use viewpager inside listview. Although you can use horizontalScrollView but it dose not recycle the view. Other third party library like this exist but I recommend you use RecyclerView with LinearLayoutManager.HORIZONTAL because it is from google and it is normally tested more than people library. And another thing is you can use other layout manager like GridLayoutManager or having for example 3 rows that swiping horizontally or other good effects like adding animation and .... that google provided with RecyclerView.
For downloading the images you can use Picasso,Volley, Universal Image Loader or a lot of other libraries that exist.
Happy Coding :-)
Not sure I'm following you, but rather than a ListView wouldn't it be simpler to use ViewPager with simple Fragment that wraps a single image at a time. That way you get horizontal swiping "for free".
Do you just want swipe to change images? Or do you want the images to scroll as you swipe? For the former, you can just use a GestureDetector. For the latter you would probably use a ViewPager. See http://developer.android.com/training/animation/screen-slide.html
I have achieved the same functionality by using ViewPager, you can either put the SeekBar and TextView in the Fragment class off which you are gonna make multiple instances for each item and add to the pageradapter,
You can also add the TextView and SeekBar above the ViewPager Layout in your main fragment layout file and change the text and data on seekbar on viewpager's on item change listener, this looks more neat and this is the approach i've used