Android - Detect when imageview or layout appear no screen - android

I have an activity that gets data from a web service. The output of the web service consists of multiple sets of one web URL and some text. The URL points to an image. Each set is displayed by creating a linear layout which contains an imageview and textview. So, for 200 sets, I would have 200 layouts, 200 imageviews, and 200 textiews. I know that a list view would be a better solution, but I've gone too far in the project to change this now.
Currently, I download all images before the activity is displayed. I download around 200 images and in the future this might rise to more than 1000.
I would like to download the images only when the imageview appears on screen. The approach I am thinking of is creating some listener or event so that once the the imageview or layout appears on screen, the download starts. I searched a lot for this but could not find a good solution. My problem is creating the listener not starting the download.
Some solutions suggested lazy load but this would still mean all images are loaded which would not be appropriate for users who have limited download capacity.
Edit: I do not want to load all images, only the ones that appear on screen. And every time the user scrolls, the new imageview that appear on screen also start downloading.

I ended up using a different and easier approach by following #Akos's solution on this link for detecting the end of the scroll view. Once the activity starts, I load 10 layouts. Once the scroll view reaches the end, I display a progress dialog and load 10 more layouts.

Related

Activity Transitions fade-in

For my app, I plan to have a grid of images and when you select one the image increases in size and the rest of the images get grayed out. I read about Activity Transitions but have never implemented that before so I'm not sure if this is the appropriate way of achieving the correct affect. I was thinking of possibly using a fragment and an animation to display the image in a larger size but how do I display the activity in the background with a grey tint to it so that it looks out of focus? I'm looking here to see what you think the most appropriate method of making this work. Here is a gif of exactly what I'm trying to accomplish.

Android: Update ImageView Background while Behind other ImageView

I'm building an app where I want to swipe images as though they were photos on a stack. In other words, if I swipe the top image I want it to animate moving in the direction of the swipe and have the next image underneath it visible the whole time. To accomplish this, I'm using a FrameLayout and two ImageView containers. I'm just alternating which one is on top. Meanwhile, as soon as a swipe occurs, the next image is loaded into the ImageView at the back using setBackground(drawable). My problem is that the ImageView at the back doesn't update it's image until I call bringToFront() on it, which means that as the top ImageView is animating, the image underneath is incorrect until the animation completes, at which point it abruptly changes to the correct image. I've tried calling invalidate() on the rear ImageView after setBackground(drawable) but this doesn't work. Anyone have any ideas on how I can get the image to update while it's behind?
UPDATE: Turns out I'm just not very on it today. I was updating the wrong ImageView and because the image loading was being done off the network, there was just enough lag to make me think it was happening after the animation completed.
Sounds to me like you wanna do something like an Image Slider.
There are great libraries existing for this purpose, this one for example:
https://github.com/daimajia/AndroidImageSlider
If you don't wanna use this, here are some tips:
Images on ImageViews are set with setImageDrawable(Drawable)
When your animation starts, set the new Image to your ImageView behind and slide the visible one away.
When the visible ImageViewhas slided away, set it's visibility to GONEand move it behind the second ImageView
Do this for every time a new image is loaded.
This should actually work.
You need a "ViewPager"
https://developer.android.com/training/animation/screen-slide.html
It has all the necessary handles to accommodate "N" number of images - also supports multiple swipe animations - default handlers - efficient memory management - prefetching - you are all in for a feast with this !!
Just make sure you get the "ImageView" in the layout of the "pages" you wish to develop on the "ViewPager".

Large Gridview 1100/1100 on android

I have to show 64/64 bitmaps in a grid of 1100/1100 but the scrolling is not smooth. What is the optimum way in displaying such ammount of image data?
This is just too much memory consumption for an android app.. I don't think you really want to load all of those at the same time. I would rethink the requirements first.
There should be a solution that still satisfies the user and does not load that many views into memory. I don't know what is the use-case here, but I would suggest implementing something like paging. Load a limited amount of items, and only if user wants to see more, then show progress bar and load more.
E.g. you can load more if user scrolls to the last item, or just create a button like "Show more". I'm not sure which solution will be okay for your app. Also, I would actually load new items into the same GridView replacing previously loaded bitmaps, because each of them requires a lot of memory. You can always control the scrolling position programmatically if needed.

Marquee of Images in android

I m working on the showing of marquee of images in my project.
I had referred this example from github.
My Problem is, i m in need of showing the images only on the top of the screen not in the entire screen(like thumb images).
In that github example, they had used LinearLayout for showing the images which is scrolled automatically.
In my case the images are dynamic , i have to retrieve them from the database.
The total of number images size may vary.
My problem is when i have reached the last image, auto scroll stops , Also if i have only two images, it won't scroll.
So i m keen to know, is there any other way to achieve marquee of images in android.

Image banner in android

if u check this steam page http://store.steampowered.com/
There is a banner which feature games, It move from right to left scroll horizontal transition which is automatic and can be scrolled left or right on press of button. I want to do same banner in android app. But right now i don't know how to start with. Need some ideas from you guys. I need efficient approach. Is it just one imageview and drawing and doing transition on its canvas. If yes then how does it work for my situation which is i am fetching images from web service via xml. SO this banner contents would be dynamic. The url of image will be in xml and i have to render those images in this banner with those transition as seen in steam page.
Thanks.
I'd suggest using a ViewFlipper and dynamically (in code) adding ImageViews. Keep in mind that loading multiple Images is very memory heavy.
You could load the shown picture +- 1 and adding/removing images on-the-fly when the shown image is switched. With this approach it would save memory and should be efficient.

Categories

Resources