The method of ScrollView nested GridView in the development of Android programming _android

Source: Internet
Author: User

This article illustrates the ScrollView nested GridView method of Android programming development. Share to everyone for your reference, specific as follows:

A few days ago in the development of the need to scrollview nested gridview, because these two controls are brought by the scroll bar, when they encounter together will be a problem, that the GridView will not show the whole, in order to solve this problem to find more than n data, A Google official reply unexpectedly is the GridView does not need to scrollview, that bullish, ah, but I have to use the swollen do it?! and continue to check, God horse rewrite the control rewrite class, that code a lump of wood has!!! Finally, the inspiration is finally realized by someone with a very vague hint.

The first is the layout

<ScrollView> ...
  <LinearLayout>
  </LinearLayout> ...
</ScrollView>

All we have to do is customize a GridView control and insert it into the middle of the linearlayout.

public class MyGridView extends gridview{
the public mygridview (context context, AttributeSet Attrs) {
 super ( context, attrs);
}
Public MyGridView {
 super (context);
}
Public MyGridView (context, AttributeSet attrs, int defstyle) {
 Super (context, attrs, Defstyle);
}
@Override public
void onmeasure (int widthmeasurespec, int heightmeasurespec) {
  int expandspec = Measurespec.makemeasurespec (Integer.max_value >> 2,
   measurespec.at_most);
  Super.onmeasure (Widthmeasurespec, Expandspec);
}


This custom control only rewrites the GridView Onmeasure method so that it does not appear scrollbars, ScrollView nesting listview is the same truth, no longer tired of

I hope this article will help you with the Android program.

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.