I am working on android. I want my list view to wrap its content horizontally and not to fill all the width. The wrap_content properties is not working. What to do?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As Romain Guy (Google Engineer works on UI toolkit) Said in his post
By setting the width to
wrap_contentyou are telling ListView to be as wide as the widest of its children. ListView must therefore measure its items and to get the items it has to call getView() on the Adapter. This may happen several times depending on the number of layout passes, the behavior of the parent layout, etc.So if you set the layout width or layout height of your ListView to
wrap_contentthe ListView will try to measure every single view that is attached to it – which is definitely not what you want.Keep in mind: avoid setting
wrap_contentfor ListViews or GridViews at all times, for more details see this Google I/O video talking about the world of listview