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