ScrollView nested listview in Android displays only one line of solution

Source: Internet
Author: User

ScrollView nested listview in Android displays only one line of solution

Solution 1:

Removing the ScrollView control that contains the ListView control directly from the layout file leaves the ListView control, which is the simplest and quickest solution.
If you must include a ListView in ScrollView, refer to the

Solution 2:

 Public void showlist() {listNewArraylist for(inti =0; I <8; i++) {hashmap<string, string> map =NewHashmap<string, string> (); Map.put ("Name","Zhang San"+ i); Map.put ("Phone","1333333333"+ i);        Datahashmaps.add (map);        } System.out.println (Datahashmaps.size ()); Simpleadapter adapter =NewSimpleadapter ( This, Datahashmaps, R.layout.item,NewString[] {"Name","Phone"},New int[] {r.id.name, r.id.phone});        ListView ListView = (ListView) Findviewbyid (R.id.list); Listview.setadapter (adapter);//Treatment solutions:        intTotalheight =0;//If no data adapter is set, the ListView does not have subkeys and returns.          for(intindex =0, Len = Adapter.getcount (); Index < Len; index++) {View ListViewItem = Adapter.getview (Index,NULL, ListView);//Calculate the width height of the child viewListviewitem.measure (0,0);//Calculates the height of all children andTotalheight + = Listviewitem.getmeasuredheight (); } viewgroup.layoutparams params = Listview.getlayoutparams ();//Listview.getdividerheight () Gets the height of the delimiter between children        //Params.height Setting the ListView to fully display the required heightParams.height = Totalheight + (listview.getdividerheight () * (Adapter.getcount ()-1));    Listview.setlayoutparams (params); }

ScrollView nested listview in Android displays only one line of solution

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.