Android ScrollView nested listview

Source: Internet
Author: User

nesting in ScrollView using the ListView, theListView only displays a little more than one line of content

Solution:

 Public classUtility { Public  voidSetlistviewheightbasedonchildren (ListView listview) {//get the adapter for the ListViewListAdapter ListAdapter =Listview.getadapter (); if(ListAdapter = =NULL) {                         return; }                                   intTotalheight = 0;  for(inti = 0, Len = Listadapter.getcount (); i < Len; i++) {//Listadapter.getcount () returns the number of data itemsView ListItem = Listadapter.getview (i,NULL, ListView); Listitem.measure (0, 0);//Calculate the width height of a child viewTotalheight + = Listitem.getmeasuredheight ();//to count the total height of all children} viewgroup.layoutparams params=Listview.getlayoutparams (); Params.height= Totalheight + (listview.getdividerheight () * (Listadapter.getcount ()-1)); //Listview.getdividerheight () Gets the height of the delimiter between children//Params.height finally get the entire ListView full display required heightlistview.setlayoutparams (params); }    }

called after the Setadapter method

New Utility (). Setlistviewheightbasedonchildren (lv);

Reprint: http://jackxlee.blog.51cto.com/2493058/666475

Android ScrollView nested listview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.