3, to ScrollView set properties: Android:fillviewport= "true"
The test found that if the ListView load of data, it can be solved, but when the ListView load more data, still can not show the full, and this time ListView itself can not scroll.
Three, there are two ways to solve the problem
1, in the calculation of ListView total height and set
ListView ListView = (ListView) Findviewbyid (ID);
Youradapter adapter = new Myadapter ("Initialize your adapter");
Listview.setadapter (adapter);
Setlistviewheightbasedonchildren (ListView);(call a custom method after Setadapter)
Copy Code code as follows:
/**
* @param ListView
*/
private void Setlistviewheightbasedonchildren (ListView ListView) {
ListAdapter listadapter = Listview.getadapter ();
if (ListAdapter = = null) {
Return
}
int totalheight = 0;
for (int i = 0; i < Listadapter.getcount (); i++) {
View ListItem = Listadapter.getview (i, NULL, ListView);
Listitem.measure (0, 0);
Totalheight + + listitem.getmeasuredheight ();
}
Viewgroup.layoutparams params = Listview.getlayoutparams ();
Params.height = Totalheight
+ (Listview.getdividerheight () * (Listadapter.getcount ()-1));
Listview.setlayoutparams (params);
}
Use this method to note that each item of the child ListView must be linearlayout and cannot be otherwise, because other layout (such as relativelayout) do not rewrite onmeasure (), so the Onmeasure () Throws an exception when.
2, Custom ListView, Overload Onmeasure () method, set all display
Copy Code code as follows:
Package com.meiya.ui;
Import Android.widget.ListView;
/**
*
* @Description: Simple implementation of embedded ListView in ScrollView
*
* @File: Scrollviewwithlistview.java
*
* @Paceage Com.meiya.ui
*
*
* @Date 03:02:38
*
* @Version
*/
public class Scrollviewwithlistview extends ListView {
Public Scrollviewwithlistview (Android.content.Context context,
Android.util.AttributeSet attrs) {
Super (context, attrs);
}
/**
* Integer.max_value >> 2, if not set, the system default setting is to display two
*/
public void onmeasure (int widthmeasurespec, int heightmeasurespec) {
int expandspec = Measurespec.makemeasurespec (Integer.max_value >> 2,
Measurespec.at_most);
Super.onmeasure (Widthmeasurespec, Expandspec);
}
}
The above can solve ScrollView embedded listview, but there is a problem is the first time to enter the interface dynamically loaded ListView items after the page will jump to the ListView first child, this very egg pain,
Helpless and do not know how to solve, first use
Copy Code code as follows:
Scrollview.post (New Runnable () {
Let ScrollView jump to the top and must be placed in the runnable () method
@Override
public void Run () {
Scrollview.scrollto (0, 0);
}
});
This method over, want to have to know friends also give a point solution
3. Use ScrollView +linearlayout to add a list using the AddView () method.