I have a ListView and one of the rows (the first one) is a ViewFlipper.
Now, My problem is that when the ViewFlipper is scrolled out of the screen and back it gets reused. Usually it is a good thing to reuse only, but in my case when the ViewFlipper is recycled its starting from scratch.
I have 5 images in it and for example if the ViewFlipper was on the second image and you scrolled it out of the screen and back, its getting back to the first image. The timing and images are important since it is in sync with other components on screen and after reusing its out of sync.
So, How can I make the ViewFlipper continue running when its out of the screen so it will get back to the exact position and timing when its back on?
To prevent the recycling of the row containing the ViewFlipper(and because this row is the first one) you could simply set it as the header view for the ListView(but you'll need to set the header view before setting the adapter). Another approach would be to keep somewhere the current position in the ViewFlipper and when the row containing this ViewFlipper will be requested you would reset the ViewFlipper's position based on that saved position in the getView method.
Related
I am animating views between two RecyclerView. The first one is something like a list of folders showing the first item as cover, clicking it opens a new view showing the folders content animating the cover to the first item. Clicking back animates all visible views back to the folder where they came from (the cover being the top most view). This looks great as long as the opened folder shows the first item. If I scroll down the first item will be offscreen and the back animation does not look that good anymore because the cover view is not animated (I'm only animating all visible views currently).
What I think would work is following: the LayoutManager could position the first item at a position shortly offscreen and keeps it as a special view in it's pool so that u always can access the first view and when I animate back to the folder view I can animate the cover in addition to all other currently visible items ( the cover will be animated from top of the screen).
This means I need following:
the LayoutManager must handle the first item as a special one that is not recycled (I may need it any time for the back animation)
the first item must always be layed out (either at the default position in the list, if it is visible or offscreen directly above the screen), again because I may need it at any time for the back animation
Can someone help me where to start here? I think this is possible with extending the LayoutManager but I don't know where to start...
Have you tried the following?
recView.getRecycledViewPool().setMaxRecycledViews(TYPE_XXXX, 0);
I have stumbled upon a problem regarding the RecyclerView. The situation is as follows:
I navigate from one Activity to another, the second one having a RecyclerView
The second activity reads an index out of the Intent and jumps its RecyclerView to that position (so it may "start" in the middle, from the user perspective)
The RecyclerView houses a list of news, each one having a network-obtained thumbnail
The thumbnails are obtained using Glide, with a placeholder (so a View inside a ViewHolder is at first inflated with height X, which may change after the thumbnail is obtained)
Now the problem is that when the user scrolls up from the item they started up, the ViewHolder is created and Glide makes a request for a thumbnail. It results in the list item having some height and changing it a second later, after the thumbnail is obtained, which in turn results in a nasty "jump" (because of the size change). It only happens 3-4 times, until enough ViewHolders get created to handle the whole RecyclerView.
Any idea how to prevent this? Ideally I would like to make the item above current to expand upwards.
I already tried making the items stack from the bottom, but it does not solve the issue, just makes it happen for the below items instead of the above ones. Also, I can not and don't want to predict the size of the obtained thumbnail.
I would use a place holder image in the Recycled View. And replace that image when it becomes available (downloaded).
This only works of course if you know the size of the tumbnails.
I need a component that works like the picture below but I'm having trouble coming up with some kind of decent solution that works.
I want the list to have a center locked selection but being scrollable with the d-pad. This is for an application running on a TV so no need for touch scroll. So when pressing down on the remote d-pad the list will scroll and a new item will size up and the current selected one will size down and the new selection will still be in the middle.
I've tried doing this using a ListView that I extended and programmatically scrolling when pressing down or up. On scroll finished I called notifyDatasetChanged() on the ListView for re-inflating of the childs and in the ListViews adapters getView() I made the animation of the view located at the current selected position.
This is not optimal since I need to call notifyDatasetChanged(), which re-inflates all visible views, for the animation to apply. The UI becomes laggy when doing this and scrolling fast. It's also not possible to make som kind of compress animation when current selected item goes out of selection. There is also some trouble with the end items (read views) such the first or last in the list when doing animation of them, the may sometimes go out of screen.
I think that his must have been done before and maybe I'm missing it when searching for an answer.
Have anyone done something similar or do you have some suggestions of how this can be achieved? Maybe I'm just starting of with the wrong component here..
Regards,
Kristoffer
I am creating layouts at run time using heavy data, and adding these layouts to a scroll view. After the view get created, its working fine. The problem here is, the data is very heavy and it takes more than a minute to create the screen, which is not so good user experience. I want to create layouts only for the part of screen that are visible, and rest I can create on scrolling the scroll view. Pls suggest how is that possible? Also, If someone has a better approach, Pls suggest.
You can start by creating only a set number of views each time[1], but always add a dummy 'loading' view at the end of the list if there are more views 'pending'. As soon as the user scrolls the ScrollView at the end of the list, start loading the next part of views on a background thread, and as soon as they are built, remove the dummy loading view, and add the new views into your container.
An other approach would be to start loading the next group of views, as soon as the previous group is done finish, but that might be a waste of resources.
An even better approach, is to combine those two methods described, and always have the next group of views being created, if the user is halfway done scrolling to the end
You can check how to know when the scrollview scrolls to the bottom here: Android: Detecting When ScrollView Hits Bottom
[1] Since you care about UX I would suggest that the number of rows should depending on the row's height and device max height. I.e. 4 views on a small device, 6 on a medium, 10 on a large.
I have a ViewPager that contains ImageViews downloaded from the net and it slides just fine when my ListView (in another separate layout) is not initialized.
But the problems start when my ListView is created. The ViewPager still "slides" but only slides about 1/4 of the way, lags, then loads the next ImageView correctly.
All of the network and bitmap operations are done using AsyncTask. I've also used the RemoteImageCache API from Singly API which works pretty well.
Any ideas as to why ViewPager's swipe is lagging?
The slow down was caused by the ListView calling getView more than necessary (more than 3x per item in my list).
According to this solution, the ListView's width and height must be given specific values and not wrap_content or else getView() will be called multiple times.
it's just because of list view scroll is conflict with view pager scroll..
if you want to know about this just set list view visibility gone don't remove code listView.setAdapter(adapter) then try view pager will slide properly.
Recently (2020), must be to implement a ViewHolder class to you get speed, or, refactoring with RecyclerView, it depends of the size of your list and the time that you have to execute this methods, like my software was already production stage, i preferred use ViewHolder class, the speed gain came to be 40%, sufficient to me, if you need the more speed, must be to use RecyclerView (refactoring your listview, edit .xml, your adapter, use Linear or Grid layout manager...).