Android ListView nested GridView Usage Tips

Source: Internet
Author: User

You may need to use the ListView nested GridView scenario in the development process, but in Android, you cannot embed another component that has scrollbar in a component that has scrollbar, because this is unscientific, confusing the sliding event, Causes only one or two rows of data to be displayed. Then change the idea, first let the child control the contents of all display, disable its scrolling. If the scope of the parent control is exceeded, the scrollbar scrolling display of the parent control is displayed, and the idea is that it is the code.
The specific method is to customize the GridView component, which inherits from the GridView. Overloaded Onmeasure Method:

 Public classMyGridView extends GridView { PublicMyGridView (Android.content.Context Context, Android.util.AttributeSet attrs) {Super (conte      XT, Attrs); }    /** * Set does not scroll*/       Public voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) {          intExpandspec = Measurespec.makemeasurespec (Integer.max_value >>2, Measurespec.at_most);        Super.onmeasure (Widthmeasurespec, Expandspec); }    }  

Where the Onmeasure function determines the height and width of the component display;
The first function in the Makemeasurespec function determines the size of the layout space, the second parameter is the layout mode
Measurespec.at_most means how much control the child control needs to expand to how much space
In the same vein, the ListView also applies

Android ListView nested GridView Usage Tips

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: 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.