How to set large number of items in ViewFlipper in Android - android

I have a ViewFlipper and an ImageView in it.I have large number of Images with me to load to the Imageview at run time.If the number of images is less its working fine.How can i achieve Image flipping with large number of images.Please help.

I ran into this same issue. If you are aiming at Honeycomb and newer advices use AdapterViewFlipper instead. You can pretty search/replace ViewFlipper for AdapterViewFlipper in your code (many methods are shared between the two), and then of course you need to pair it with an adapter extended from BaseAdapter. I did not find a lot of examples of doing so that were specific to AdapterViewFlipper, but the process is largely the same as for GridView, ListView, etc. This brief example helped get me going: http://www.mkyong.com/android/android-gridview-example/.

Related

Recyclerview scroll lag

I have multiple elements in my recyclerview's row -> By multiple I mean multiple in number as well as multiple in type i.e mutliple imageviews, textviews etc.
Following is the gist so that you can see all the elements: https://gist.github.com/Harshhb101/55e25da72e3a474aeeb422d5e231d3e3
The issue is that I need to hide/show these elements based on a parameter which can have upto 10 values. Thus I will have 10 types of rows. Currently I have created only one layout for the row have elements for all types of rows and in some mobiles, the scroll has a lag. Majorly I am getting the lag where the rows have images. I am using Glide to load the images. Following is the gist for the onBindView: https://gist.github.com/Harshhb101/e10feb2cccda9d698ff06487bbb879ef
I did look up on stackoverflow but could not find anything solid but came upon using multiple viewholders. My question is that if I refactor my code, will it make a substantial difference by using multiple viewholders? Or is there something wrong in my approach that could be fixed to get a good scoll.
You need to make your RecyclerView images smaller to save memory and cache them. Read this.
Also if your ViewHolder contains images that has size wrap_content then images are loaded full size what is really bad for performance for example if view size on screen is 48dp x 48dp and picture is full HD, then full HD drawable going to be loaded in to memory what is making your scrolling slow and not smooth.
I suggest using fixed size in ViewHolder or override image size when loading in Glide
Please declare many view type instead of one view type for many kind. It's actually make the code more readability, but not much the reduce the lag because the recycle view/listview is have the reused mechanism.
Recommended to use fixed size in RecycleView.
I saw the Glide used for image loading. So did you config the cache?
I have doubt that you loading the big resolution image
After looking into the code i found couple of improvements.
Don't make God ViewType (One view type for all kind of views). instead create
individual viewtype for each kind of posts. so it'll eliminate the rendering cost of all the views and making them visible and invisble at runtime.
Reference demo of recyclerview with multiple viewtypes
Use some image loading libraries so that you dont have to handle caching images and bitmap related manipulations (Picasso will be good).
Picasso
And lastly avoid doing heavy tasks in onbind() instead prepare your data class specifically for recyclerview (if much caluclation required like heavy string manipulations etc) before setting recyclerview adapter.

Android: what's the best view to use when making an image tile grid view?

Got some good feedback. Originally wanted infinite scroll. Removed it. I am also an interested in a solution with pagination or that just handles a simple case of the first 20 results to start. The main thing I want to know is the best types of views to use. Question was very vague at first. Narrowed the scope of it, too.
I want a view that fills the phone or tablet's screen with tiled images from an api.
How I'm thinking about doing this:
putting a GridView in my layout
using the Picasso library by Square to load the images (possibly do more, not sure what it can do for me)
making an adapter to the GridView
doing a query to my api (in this case getting popular movies)
processing the query results and turning them into an ArrayList of Strings or Uris with the image locations (for popular movie posters)
passing the list to the adapter to the GridView so it can show the images.
I don't I know enough about Android to think this through fully yet. I'm in the process of learning.
Any suggestions for better design, tutorials on similar things, or things that may make this easier/better?
Thanks!

how to layout images

I have a lot of images in scrollview, I would like to know how to layout them so they would be seen the same on different resolutions. Like if I rotate screen some images would fill the gap.(All activity is only images)
You can use GridLayout.
Check Heterogeneous GridLayout,GridLayout and Row/Column Span Woe.
It might helpful for you.
This issue is behond displaying an image on a gridView but rather about memory limitation and caching(recycling and reusing etc..)
Take a look at this link Displaying Bitmaps Efficiently and try to download a sample on the left called BitmapFun.zip

Android gallery of drawables

I'm creating a simple Gallery of drawables - each of them is almost the size of a screen, so they require quite much memory. For each entry I'm creating a custom LinearLayout with ImageView and TextView for the title. As most of you know, android Gallery doesn't recycle views so it gallery will crash easily on low-memory phones (after loading 4 drawables on 16mb ram limit, in my case).
Here's the simple question - how do you implement such gallery, so it won't run out of the memory? How do you recycle these images? A working code example would be great.
Few notes:
inSampleSize isn't a way to go, I can't scale these images down
Calling recycle() on Drawable's loaded from resource is impossible, as it will crash on Android 4.0+ (it will recycle the drawable in their internal cache)
Don't ask me to post the code, as there is no.
You shouldn't be using Gallery because it's deprecated. Especially since there isn't any code written so far. The documentation suggests using a HorizontalScrollView or ViewPager.
I feel a ViewPager is what your looking for because it will only keep at most 3 pictures in memory and handels all the recycling for you. Here is a post with more information about how to implement one android viewPager implementation

Android: ViewFlipper & multiple images?

Hey, I checked tons of tutorials and guides but somehow can't find it...
I need to include multiple images in my Android app. It's like an image viewer/slideshow.
Currently I switch between pictures from /drawable-mdpi dir simply with ImageView and adapter, using gestures to left/right. Works but nothing impresive :/
Basically I could use something like Android (2.1) gallery with some image show animation.
1st question: what's the best way to include many (50-100) fullscreen images in App?
2nd: is it possible to use ViewFlipper animations directly to images? or do i have to somehow populate Views?
1st question: what's the best way to include many (50-100) fullscreen images in App?
Any approach that only involves a couple of images being in memory at one time. Full-screen images are large; you will run out of RAM.
2nd: is it possible to use ViewFlipper animations directly to images? or do i have to somehow populate Views?
You would have to use ImageViews as the children of the ViewFlipper.
I would recommend sticking with what you have and just apply animations.

Categories

Resources