Resolves an issue where Android's ListView nesting cannot be scrolled in ScrollView

Source: Internet
Author: User

The use of scrollbars is a consequence of the uncontrolled height and width,

Before encountering a page that already has a scrollview need to add a list ListView, and then found that the ListView only see the first two rows of data, the following can not see, pull the scroll bar is just scrolling the entire page, not a ListView.

Method 1: Let the outside Scollview hand over the scrolling permission, because the listview itself has scroll bars.

Method 2: Calculate the list height after the content is loaded, and then set the height.

As long as you set the adapter to your ListView, and then reset the listview height, the idea is to figure out the height of each row, set the height of the listview to the height of each row * number of lines + the height of each line divider.

1  Public voidSetlistviewheightbasedonchildren (ListView listview) {2ListAdapter ListAdapter =Listview.getadapter (); 3         if(ListAdapter = =NULL) {    4             return; 5         }    6         intTotalheight = 0; 7          for(inti = 0; I < Listadapter.getcount (); i++) {    8View ListItem = Listadapter.getview (i,NULL, ListView); 9Listitem.measure (0, 0); TenTotalheight + =listitem.getmeasuredheight ();  One         }     AViewgroup.layoutparams params =Listview.getlayoutparams ();  -Params.height =Totalheight -+ (Listview.getdividerheight () * (Listadapter.getcount () + 1));  the listview.setlayoutparams (params);  -}

When the ListView is passed in, the method changes its parameters and sets its height. 0.0

Resolves an issue where Android's ListView nesting cannot be scrolled in ScrollView

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.