Re: [android-developers] Re: How to detect if a view is on screen

2011-09-06 Thread Marc Van Daele
Hello Ed,

Thanks for your answer but I'm not sure a ListView will work (though I will
look at the video).
Isn't a ListView limited to Vertical scrolling? (at least the javadoc says
so)

Kind Regards,

Marc



2011/9/6 Ed edscha...@gmail.com

 Hi Marc,

 Have a look at ListView. It's probably done most of the hardwork for you if
 you just write your own adapter. Just make sure you get your getView
 correct.

 Watch a couple of Romain Guy's videos from Google I/O e.g.
 http://www.youtube.com/watch?v=wDBM6wVEO70

 Should help get you started in the right direction.

 Cheers,

 Ed

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to detect if a view is on screen

2011-09-06 Thread Indicator Veritatis
I would have said use ScrollView, but that too is limited to
vertical scrolling. So now I have to ask: do you really HAVE to have
the scrolling done horizontally? You might be in for a harder time if
you insist on this.

On Sep 5, 11:29 pm, Marc Van Daele marc.van.dael...@gmail.com wrote:
 Hello Ed,

 Thanks for your answer but I'm not sure a ListView will work (though I will
 look at the video).
 Isn't a ListView limited to Vertical scrolling? (at least the javadoc says
 so)

 Kind Regards,

 Marc

 2011/9/6 Ed edscha...@gmail.com

  Hi Marc,

  Have a look at ListView. It's probably done most of the hardwork for you if
  you just write your own adapter. Just make sure you get your getView
  correct.

  Watch a couple of Romain Guy's videos from Google I/O e.g.
 http://www.youtube.com/watch?v=wDBM6wVEO70

  Should help get you started in the right direction.

  Cheers,

  Ed

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How to detect if a view is on screen

2011-09-06 Thread Indicator Veritatis
Hah, I should have thought of this name! 'HorizontalScrollView' has
been supported since API level 3, and it sounds like just what you
want.

On Sep 5, 11:39 pm, Indicator Veritatis mej1...@yahoo.com wrote:
 I would have said use ScrollView, but that too is limited to
 vertical scrolling. So now I have to ask: do you really HAVE to have
 the scrolling done horizontally? You might be in for a harder time if
 you insist on this.

 On Sep 5, 11:29 pm, Marc Van Daele marc.van.dael...@gmail.com wrote:

  Hello Ed,

  Thanks for your answer but I'm not sure a ListView will work (though I will
  look at the video).
  Isn't a ListView limited to Vertical scrolling? (at least the javadoc says
  so)

  Kind Regards,

  Marc

  2011/9/6 Ed edscha...@gmail.com

   Hi Marc,

   Have a look at ListView. It's probably done most of the hardwork for you 
   if
   you just write your own adapter. Just make sure you get your getView
   correct.

   Watch a couple of Romain Guy's videos from Google I/O e.g.
  http://www.youtube.com/watch?v=wDBM6wVEO70

   Should help get you started in the right direction.

   Cheers,

   Ed

   --
   You received this message because you are subscribed to the Google
   Groups Android Developers group.
   To post to this group, send email to android-developers@googlegroups.com
   To unsubscribe from this group, send email to
   android-developers+unsubscr...@googlegroups.com
   For more options, visit this group at
  http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: How to detect if a view is on screen

2011-09-06 Thread Marc Van Daele
In fact, I'm using HorizontalScrollView already
but I'm worried about memory consumption (I'm coming from the embedded
software world)

Inside the HorizontalScrollView  I have a LinearLayout containing a list of
my own Views
(actually a ViewGroup displaying a movie poster but also information on the
actors, description, icons for parental rating etc).

Whenever my View is first loaded (first dispatchDraw call), I load the
Bitmap for the movie poster.
But right now, I never unload this bitmap so I'm worried about memory usage.

Hence I want to release the Bitmap when the View is not on screen.
I don't think HorizontalScrollView as such (nor ListView) provides support
for this (please correct me if I'm wrong)

I looked a bit in the source code of HorizontalScrollView and noticed that
it has a private :-(  method isOffScreen(..).
Based on that code I now do something like (in the parents dispatchDraw)

 ViewGroup scroller = (ViewGroup)
getChildAt(0);//HorizontalScrollView
ViewGroup layout = (ViewGroup) scroller.getChildAt(0);//LinearLayout
for (int i = 0; i  layout.getChildCount(); i++)
{
View child = layout.getChildAt(i);
//check if an asset/event is visible
if(isOffScreenHorizontal(scroller, child))
{
 //call unload method
}
}

with isOffScreenHorizontal
private boolean isOffScreenHorizontal(ViewGroup parent, View child)
{
Rect mTempRect = new Rect();
child.getDrawingRect(mTempRect);
parent.offsetDescendantRectToMyCoords(child, mTempRect);

return !((mTempRect.right) = parent.getScrollX()
 (mTempRect.left) = (parent.getScrollX() +
parent.getWidth()));
}

Can you give feedback on this approach?

TIA,

Marc


2011/9/6 Indicator Veritatis mej1...@yahoo.com

 Hah, I should have thought of this name! 'HorizontalScrollView' has
 been supported since API level 3, and it sounds like just what you
 want.

 On Sep 5, 11:39 pm, Indicator Veritatis mej1...@yahoo.com wrote:
  I would have said use ScrollView, but that too is limited to
  vertical scrolling. So now I have to ask: do you really HAVE to have
  the scrolling done horizontally? You might be in for a harder time if
  you insist on this.
 
  On Sep 5, 11:29 pm, Marc Van Daele marc.van.dael...@gmail.com wrote:
 
   Hello Ed,
 
   Thanks for your answer but I'm not sure a ListView will work (though I
 will
   look at the video).
   Isn't a ListView limited to Vertical scrolling? (at least the javadoc
 says
   so)
 
   Kind Regards,
 
   Marc
 
   2011/9/6 Ed edscha...@gmail.com
 
Hi Marc,
 
Have a look at ListView. It's probably done most of the hardwork for
 you if
you just write your own adapter. Just make sure you get your getView
correct.
 
Watch a couple of Romain Guy's videos from Google I/O e.g.
   http://www.youtube.com/watch?v=wDBM6wVEO70
 
Should help get you started in the right direction.
 
Cheers,
 
Ed
 
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to
 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
   http://groups.google.com/group/android-developers?hl=en

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to detect if a view is on screen

2011-09-05 Thread Marc Van Daele
I didn't see my question (see below) appear in the group yet so I'm
resending.
Sorry if it appears twice.

Marc

2011/9/3 vdaele marc.van.dael...@gmail.com

 Hello,

 Suppose I have a horizontal scrollable list of say 100 movie posters
 (each in its own View)
 of which only 4 Views fit on the screen at the same time.
 When I've scrolled through the complete list once, I will have 100
 Bitmaps in memory of which only 4 are visible.

 To save memory, I want to release the Bitmaps of those Views that are
 off-screen.
 Is there an easy way to know whether a View is effectively visible or
 should I compute this myself?

 (I've looked at the onVisibilityChanged listener but this seems to
 serve a different purpose)

 Thanks for your help,

 Marc





-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to detect if a view is on screen

2011-09-05 Thread Ed
Hi Marc,

Have a look at ListView. It's probably done most of the hardwork for you if 
you just write your own adapter. Just make sure you get your getView 
correct.

Watch a couple of Romain Guy's videos from Google I/O 
e.g. http://www.youtube.com/watch?v=wDBM6wVEO70

Should help get you started in the right direction.

Cheers,

Ed

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en