The simplest method for conflicts between scrollview and listview In the android Layout

Source: Internet
Author: User

One of the most popular ways to use it is

Public class utility {
Public static void setlistviewheightbasedonchildren (listview ){
Listadapter = listview. getadapter ();
If (listadapter = NULL ){
// Pre-condition
Return;
}

int totalheight = 0; arrears
for (INT I = 0; I View listitem = listadapter. getview (I, null, listview);
listitem. measure (0, 0);
totalheight + = listitem. getmeasuredheight ();
}

viewgroup. layoutparams Params = listview. getlayoutparams ();
Params. height = totalheight + (listview. getdividerheight () * (listadapter. getcount ()-1);
listview. setlayoutparams (Params);
}< BR >} iphone5 news

This is too troublesome, and the effect is not very obvious.
A summary is as follows:
If you call this static method after setting the listview adapter, The listview can be correctly displayed in the listitem of its parent listview. However, it should be noted that each item in the sublistview must be linearlayout, but not others, because other layout (such as relativelayout) does not overwrite onmeasure (), so it will be in onmeasure () throw an exception.
another problem with nested listview (or scrollview) in scrollview is that the subscrollview cannot slide (if it is not completely displayed ), because the slide event will be eaten by the parent scrollview, if you want to let the child scrollview slide, you can only forcibly capture the slide event, some cool people posted Code in the Forum. Although I have not tried it myself, it is estimated that it is feasible.
although scrollview shows that the technical difficulties of scrollview can be broken, this design is very poor because it is difficult for users to see and operate on contents in the subscrollview. For example, a good design is that each item of the parent listview only displays a general description, and then click its item to go to another page to describe and display in detail and perform operations on this item.
find the other two simple methods without affecting them:
1. add an attribute Android: fillviewport = "true" to scrollview to display the listview in full screen.
2. specify the height of listview Android: layout_height = "420dp";

Related Article

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.