I have a custom ListView that scrolls down quite a bit. I want a background image that tiles and scrolls with the ListView.
I used the code from this answer but background images are jumpy in that at certain scrolling points the entire thing resets to what is currently the top of the viewable screen. I assume this is because of ListView optimization. How do I get around this if each item in the list has the same height? I don't need the image to load for nonexisting items, I just need the illusion of continuity.
Otherwise, tiling works just fine.
Related
I want a screen to arrange rectangles with drag & drop. Elements can be moved freely, so it's not a grid or list. I think I should use absolute positions.
My main problem is that I need an endless screen (when drag to right, scroll the screen to the right). One solution I found was to set width and height to 10000dp and a 2d scroll. Another way is to resize the container each time the user drags an element.
I need a better solution if possible. Any suggestions?
Resize the container each time the user drags an element out of the current view bounds should be the most performant idea.
By the way you should put some max size limit to the view, otherwise you will run out of RAM fast and your app will crash.
I have an app that show the tv guide for a list of channels. My UI is made from a a lot of custom views with different widths that show the tv programs, all these custom views are added into a horizontal scrollview that is added into a scrollview so my views can be scroll in 2 dimensions left-right and top-down. It all works good until i add add a lot of views and it starts to slow down very much. So i need a way to recycle views like listiew does in a scrollview maybe there is a custom made scrollview that does this, or someone has an idea how to do this, its strange that scrollview isnt backed up by an adapter like gridview and listview.
I did something similar only my Views were not connected as yours but they were all different sizes.
First you need to define if your entire area (not just viewing screen) has definitive or dynamical number of your custom views.
If you have definitive number of views and their positions you should create their position map with list of Rect's (Rect has a good function whether the xy point belongs). Then you define maximum of Views which are visible on your screen. For this to work without constant loading you should have maximum visible views + at least one line of border views of total objects. After all this you should easily have your own positioning system where you load views which are in bounds of your screen + some overhead (purpose of this is that you want your users to have smooth transition while scrolling at least for some length), if you need to load some in same time you unload (read reuse/ do not dispose objects and create them onScroll events) and place them according to your needs.
And if you want to determine which views should be visible you just go through list and ask whether Views Rect intersects with your Rect of area to be loaded.
Hope this image helps a little bit more
I know it sounds a little bit confusing and difficult to implement but you did not asked a simple question :)
Hope this helps and enjoy your work.
A ScrollView that is backed up by an adapter and recycles views is a ListView, with a couple of extra optional features on top.
Maybe you want a HorizontalScrollView that is backed by an adapter? Searching for HorizontalListView will give you a few results, ex: https://github.com/dinocore1/DevsmartLib-Android.
I have a list adapter which shows a large photo in each row. I'm fetching the bitmap off the disk in a thread in the ListAdapter.getView() method. This works fine, but it's slightly annoying that when the user is scrolling, they'll see the top of a new row coming on screen with the empty ImageView. The thread to read the bitmap off disk completes pretty quickly and then the redraw happens.
Is there a good pattern in the ListAdapter world to signal that the "next" row is in danger of coming onto screen momentarily? Ideally I'd like to start a thread to load the bitmap for this invisible row and get the bitmap into my memcache, that way if the user does scroll to this cell, the bitmap will already be loaded.
I suppose I'd need to know that (1) the user is scrolling downwards and (2) the top edge of the next invisible row is approximately 20 pixels or some value away from being visible.
Thanks
Register an AbsListView.OnScrollListener; you will be notified for the scrolling state of the list and you will also be given the current visible items. Combine these two parameters and it should be simple for you to decide whether you need to load "next" bitmaps or not.
I need to implement a list of images and buttons. I have 6 images serving as separators and a total 14 buttons with custom background. The list has a full screen (800×600) background, the separator images are 800×30 pixels and the buttons have similar size as well (all buttons have the same background image). On top of this, I need a custom scroll indicator: two blinking arrows on top and bottom. The arrows should be shown or hidden according to the scroll position.
I have some other GUI elements including a GLSurfaceView hidden using View.GONE as the list is shown on top of those.
The problem is, that this setup runs too slow on relatively powerful handsets such as the Galaxy Nexus or the Desire HD.
I tried two different approaches:
Using a ListView based on this tutorial: http://android.amberfog.com/?p=296
Put all buttons and images into one LinearLayout and use that as a child of a ScrollView. To hide and show the the blinking arrows I determine scroll position by overriding onScrollChanged (Synchronise ScrollView scroll positions - android)
Both implementation runs slow depending on the actual handset. The ScrollView implementation is usually faster but it has noticable lags on a Desire or the Galaxy Nexus while the ListView implementation is slow on the Desire HD.
Which is the best way to implement such list? Could you suggest me some guidelines how to make the implementation fast and device independent? I believe having about 20 images and buttons in a list shouldn't be a problem for these handsets.
Ok, it seems that the problem was the following:
I had a GLSurfaceView in the same activity and the list appeared above it. This was too much for the UI thread, although the list totally overlapped the GLSurfaceView and the rendering was paused when the list appeared.
I moved the list to a different activity and now it has an acceptable speed. But switching to the list is slower and when I close the list, I have to reload the surfaceview, but that is ok.
I have extended an ArrayAdapter to manage a ListView using a certain tamplate (made of 1 ImageView and 1 TextView contained in a RelativeLayout) as row of the list.
Anyway I am now facing some optimization issues. As you guys know, not all the rows are rendered at any 1 time but rather you get the rows progressively rendered when the user scrolls the list and they actually appear on the screen. Basically my problme is this:
when the list is scrolled really rapidly, the rendering engine cannot keep up with the speed and, although the images to display are cached, the placement of the images in the ImageViews of the visible rows take some time.
To be honest I was expecting the getView method to be really fast but apparently when it comes to images there are some tricks to know. Any1 wanna share ??
cheers ;)
You may take a look at my sample. It does exactly the same Lazy load of images in ListView.