Android's ScrollView nested ListView and GridView conflict Resolution _android

Source: Internet
Author: User
Then there is a problem with the ScrollView height calculation. We can not get the desired effect.
Core solution: Rewrite the Onmesure method of the ListView or GridView.
Copy Code code as follows:

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

Gridview
Copy Code code as follows:

public class MyGridView extends GridView {
Private Boolean Havescrollbar = true;
Public MyGridView {
Super (context);
}
Public MyGridView (context context, AttributeSet Attrs) {
Super (context, attrs);
}
Public MyGridView (context context, AttributeSet attrs, int defstyle) {
Super (context, attrs, Defstyle);
}
/**
* Set whether there is a scrollbar, you should set to False when you want to display in Scollview. The default is True
*
* @param havescrollbars
*/
public void Sethavescrollbar (Boolean havescrollbar) {
This.havescrollbar = Havescrollbar;
}
@Override
protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {
if (Havescrollbars = = False) {
int expandspec = Measurespec.makemeasurespec (integer.max_value >> 2, measurespec.at_most);
Super.onmeasure (Widthmeasurespec, Expandspec);
} else {
Super.onmeasure (Widthmeasurespec, Heightmeasurespec);
}
}
}

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.