Use custom ListView to solve the nested problem in scrollView
In my opinion, the custom listView control is relatively simple and can solve the problem of nesting listview in scrollView.
The Code is as follows:
public class MyListView extends ListView {public MyListView(Context context) {super(context);}public MyListView(Context context, AttributeSet attrs) {super(context, attrs);}public MyListView(Context context, AttributeSet attrs,int defStyle) {super(context, attrs, defStyle);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);super.onMeasure(widthMeasureSpec, expandSpec);}}
Local layout file:
In this way, the first item of listView instead of scrollView is displayed by default. Therefore, you need to set two items in the activity file:
lv_bought_goods.setFocusable(false);scrollView.smoothScrollTo(0, 0);