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
> 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 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 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
> >
> > > > 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