Android Development: ScrollView nested GridView Solution

Source: Internet
Author: User

Android Development: ScrollView nested GridView Solution

A few days ago in the development of the need to ScrollView nested gridview case, because these two controls are self-contained scroll bar, when they encounter together, there will be a problem, that is, the GridView will display incomplete.

Workaround, customize a GridView control

public class MyGridView extends GridView {Public MyGridView (context context, AttributeSet Attrs) {Super (context, attrs);}
Public MyGridView (Context context) {Super (context);}
Public MyGridView (context 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);       }  }

The custom control simply overrides the GridView Onmeasure method so that it does not appear in the scroll bar, ScrollView nested listview is the same reason, no longer repeat.

XML Layout Code

<scrollview android:layout_height= "Wrap_content"Android:layout_width= "Fill_parent" android:id= "@+id/scroll_content" ><com.yourclass.mygridview xmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@+id/grid_view" android:layout_width= "Fill_parent"android:layout_height= "Wrap_content" android:numcolumns= "Auto_fit"android:horizontalspacing= "1dip" android:verticalspacing= "1dip" android:columnwidth= "15 0dip "android:stretchmode=" columnWidth " android:gravity=" center "> </ com.yourclass.mygridview> </ScrollView>

Java calling code

MyGridView gridview = (MyGridView) findViewById(R.id.grid_view);  gridview.setAdapter(new ImageAdapter(this));

Android Development: ScrollView nested GridView Solution

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.