[android-developers] Re: How to make a ListView adapt to dynamic element sizes?
What am I missing? How can I programmatically tell a container view to look at its children again in order to resize if necessary? example in api demos --- Views/Lists/6.ListAdapter Collapsed On Wed, Apr 1, 2009 at 1:12 PM, Matthias m.kaepp...@googlemail.com wrote: Hi, I am struggling over another layouting problem again. I render a ListView with ellipsized TextView elements, but those text views can expand in size when the user clicks it. The problem is: If the ListView doesn't already take the whole screen (e.g. because the total height of all visible elements is smaller than the screen height), then when expanding an element, the ListView's size doesn't also expand accordingly, still obscuring most parts of the now taller text view. I have tried practically everything that seemed reasonable to me to make the ListView get aware of the new height of its children, including calls to: invalidate() measure() recomputeViewAttributes(textView) on all participating views (the list view and its elements), but nothing works. What am I missing? How can I programmatically tell a container view to look at its children again in order to resize if necessary? Thanks! Matthias --~--~-~--~~~---~--~~ 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 make a ListView adapt to dynamic element sizes?
Well, I found a really ugly workaround. That workaround is based on my observation that the problem described does only occur if the ListView's layout height is set to WRAP_CONTENT. So, since I use a custom list adapter, I now call listView.getLayoutParams().height = LayoutParams.FILL_PARENT whenever a text view is about to be expanded... the reason I do not statically set its height to FILL_PARENT is because then it will draw line separators below the last element, which looks ugly if it doesn't expand to the bottom of the screen. It works... but, yuck! --~--~-~--~~~---~--~~ 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 make a ListView adapt to dynamic element sizes?
If your list-view uses a (list-)adapter (or a subclass of this), did you try to call notifyDataSetInvalidated() on the adapter? This will cause your adapter's getView(int position, View convertView, ViewGroup parent) to be called again and you can handle your changed list-item in there. On Apr 1, 5:24 am, matthias m.kaepp...@googlemail.com wrote: Well, I found a really ugly workaround. That workaround is based on my observation that the problem described does only occur if the ListView's layout height is set to WRAP_CONTENT. So, since I use a custom list adapter, I now call listView.getLayoutParams().height = LayoutParams.FILL_PARENT whenever a text view is about to be expanded... the reason I do not statically set its height to FILL_PARENT is because then it will draw line separators below the last element, which looks ugly if it doesn't expand to the bottom of the screen. It works... but, yuck! --~--~-~--~~~---~--~~ 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 make a ListView adapt to dynamic element sizes?
ListView supports the WRAP_CONTENT height mode but it is really not meant for that. First of all, having a ListView in WRAP_CONTENT is very costly in terms of layout. It is also meaningless. What does WRAP_CONTENT mean for a ListView since the goal of ListView is to virtualize its children? Because of this, ListView just does not support growing or shrinking when you modify its adapter. You should simply use FILL_PARENT for your ListView. And you may find the last divider ugly but *every* ListView in the system behaves that way. Your WRAP_CONTENT ListView just looks different from the rest of the system for absolutely no good reason. Consistency matters. On Wed, Apr 1, 2009 at 6:40 AM, Streets Of Boston flyingdutc...@gmail.com wrote: If your list-view uses a (list-)adapter (or a subclass of this), did you try to call notifyDataSetInvalidated() on the adapter? This will cause your adapter's getView(int position, View convertView, ViewGroup parent) to be called again and you can handle your changed list-item in there. On Apr 1, 5:24 am, matthias m.kaepp...@googlemail.com wrote: Well, I found a really ugly workaround. That workaround is based on my observation that the problem described does only occur if the ListView's layout height is set to WRAP_CONTENT. So, since I use a custom list adapter, I now call listView.getLayoutParams().height = LayoutParams.FILL_PARENT whenever a text view is about to be expanded... the reason I do not statically set its height to FILL_PARENT is because then it will draw line separators below the last element, which looks ugly if it doesn't expand to the bottom of the screen. It works... but, yuck! -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---