Optimal Solution for ScrollView nested ListView conflicts, scrollviewlistview
After the project is done, you will find that ScrollView nesting ListVew or GridView is very common, but you will also find various strange problems. Based on your personal experience, it is now the easiest way to list common problems and code.
Question 1: The ListVew data nested in the ScrollView is not fully displayed. I encountered a maximum of two existing data entries.
Solution: rewrite ListVew or GridView. There are still many solutions on the Internet, but they are not easy to use or complex.
@ Override
/** Only override this method to make ListView adapt to ScrollView */
Protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec ){
Int expandSpec = MeasureSpec. makeMeasureSpec (Integer. MAX_VALUE> 2,
MeasureSpec. AT_MOST );
Super. onMeasure (widthMeasureSpec, expandSpec );
}
Question 2Open the page layout of ScrollView with ListVew. The default start position is not the top.
There are two solutions that are quite useful:
First, you can set the Gridview or ListVew in it to avoid getting the focus.
Gridview. setFocusable (false); listview. setFocusable (false );
Note: Setting android: focusable = "false" in xml layout does not take effect.
Method 2: You can set myScrollView. smoothScrollTo () on the Internet );