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);
}
}
}