Multiple listview entries in linearlayout implement scrolling.

Source: Internet
Author: User

If you are idle, find some information on the Internet to learn. You can see the implementation of the listview rounded corner design on the 360 moji weather setting interface on the Internet. But encountered problems ....

Moji weather map:

Here we use the shape in Android to implement it. It is relatively simple to implement, but it is a little troublesome during scrolling...

When multiple listview lists exceed its parent control linearlayout, each of them will have its own scrolling, which is not the expected effect, I first wanted to add a layer of scrollview outside linearlayout, but as a result, we encountered a problem of scrollview and listview conflicts, which would cause incomplete display of listview. Borrow onlineCodeUnderstanding: We only have to fix the height of the listview so that it will not conflict with scrollview if it is not adjusted automatically. The Code is as follows:

/***** Dynamically set the height of the listview ** @ Param listview */Public void setlistviewheightbasedonchildren (listview) {listadapter = listview. getadapter (); If (listadapter = NULL) {return;} int totalheight = 0; For (INT I = 0; I <listadapter. getcount (); I ++) {view listitem = listadapter. getview (I, null, listview); listitem. measure (0, 0 );//You cannot obtain the view width before creating a view.  Before that, we must select measure. 
Totalheight + = listitem. getmeasuredheight ();} viewgroup. layoutparams Params = listview. getlayoutparams (); Params. height = totalheight + (listview. getdividerheight () * (listadapter. getcount ()-1); // Params. height + = 5; // If without this statement, the listview will be // A // little short // listview. getdividerheight () obtains the height occupied by separators between subitems. // Params. the height finally shows the required height for the entire listview. setlayoutparams (Params );}

After we call the setadapter of listview, this method will be OK, so that the height of the listview is customized according to the content.

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.