I want to add lazy loading feature to HorizontalScrollView, It has
linearlayout as a child and i am addding to linearlayout,
I am interested in listening to the event when the child view is out
of the visibility area, I see in linearlayout implementation it does
not call either dispatchViewVisibility or onDraw on child view , why i
want that because bitmap attached to the child view can be recycled
and create bitmap again when child view is visible (well that is a
separate part ,How can i create that bitmap very fast, I am planning
to use opengl for that) but the question is how can make such custom
view.
I can not use gallery view because it does not solve my purpose
I saw that viewgroup has feature of dispatchingViewVisibility and
dispatchOnDraw but not sure how to use that with
HorizontalScrollView.?
All i am doing to prevent Out of Memory issue
Any suggestion and help would be appreciated
thanks
Do not use HorizontalScrollView. Instead, use the ViewPager component that was added to the Android Compatibility Library, as it is designed for this sort of scenario. Here is a blog post that explains a bit more.
Related
I am trying to design a recycler view with expandable design , it will have groups which on click would open and show child views. But the child views need to support linear layout and grid layout as well.
Currently I am using a recycler view within another recycler view to achieve the same, and used expandable layout for expanding collapsing items. This does get me the desired effect but neither is it a good programming practice and nor is it bug free. It does some unexpected things at all times, which is really annoying and a bad UX experience.
Please tell me other reliable and bug free ways to do it.
This image is approximately what I am trying to achieve. Cannot show the actual work I have done because of company policy.
I am not asking to source code to solve my problem, but some general design directions to achieve the same goal. As mentioned before, what I did, using recycler view inside another did do the trick, but also created other problems(unpredicatble behaviour to say the least.)
It seems like using nested scroll view and setting the inner recycler views to 'setNestedScrollingEnabled(false)' did the trick. Now I can make what I wanted to after all.
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
I am dynamically adding around 150 linearlayouts to a scrollview in a grid-like layout. If I set the background resource to a drawable for each of them using setBackgroundResource(R.drawable.x), the scrollview shows extremely noticeable lag and choppiness, even though the drawable is a simple colour and border.
If I remove the call to setBackgroundResource, the scrollview is smooth again.
Is this expected to happen with so many views containing backgrounds? If so, how would I go about making a grid with custom backgrounds for each cell?
You're going to want to use a list view in your scroll, and you're going to want to use a ListAdapater:
http://developer.android.com/guide/topics/ui/layout/listview.html
http://developer.android.com/reference/android/widget/Adapter.html
Basically what's going on is you're loading a large number of images into memory, and the scroll view by default doesn't do a very good job of managing releasing and inflating these resources.
Using methods similar to the above, with some custom image management, I've managed to get thousands of views running smoothly on a scroll.
It seems like you're trying to create your own list view implementation so that you can set your own layouts for each row. I don't recommend doing this. Instead, use the default list view implementation provided by Android and instead of setting a default ArrayAdapter instance on the list view, subclass ArrayAdapter, override the getView method, and return your custom layout.
I highly recommend you check out this tutorial for a more thorough explanation:
http://www.ezzylearning.com/tutorial.aspx?tid=1763429
I want to add lazy loading feature to HorizontalScrollView,
Linearlayout as a child and i am addding to linear layout, I want that when image view is out of focus then in horizontal scroll view that can not load but when its come in visible area it will load images(Kind of lazy loading).
I want that because bitmap attached to the child view can be recycled and create bitmap again when child view is visible but the question is how can I make such custom view. I can not use gallery view because it does not solve my purpose I saw that viewgroup has feature of dispatchingViewVisibility and dispatchOnDraw but not sure how to use that with HorizontalScrollView.?
I just want to load fast images in horizontal scroll view which I am adding pro grammatically and prevent OOM issue.
Any suggestion and help would be appreciated
Thanks in advance.
you can use the ViewPager , or use a horizontalListView as created by others (here ,here, and here for example) .
in the adapter , set an asyncTask to load the info , and if you get to go to a new view that was recycled , cancel the asyncTask it had so that it will start a new one .
try to use ViewPager. Acts like HorizontalScrollView but uses adapter as child views source.
May be a dumb Question.But still, is it possible to reuse the views in viewflipper?
Now,i have three imageviews in a viewflipper.is it possible to have a single imageview and change the source to it?
You can probably reuse view if you want to take care of the bookkeeping your self. However the viewflipper requires at least 2 views. From the Android ViewFlipper Docs:
Simple ViewAnimator that will animate between two or more views
that have been added to it. Only one child is shown at a time. If
requested, can automatically flip between each child at a regular
interval.
You would have to remove the ImageView from the ViewFlipper and then put it somewhere else. You can't put it into two ViewGroups at the same time (you'll get an exception that the view has already a parent).
But this is an overhead which you simply don't need to do. Simply create new ImageViews and use them. The memory consuming part of an ImageView is not the object itself but the bitmap it draws so I really recommend to read this article.