想要使用ScrollView来实现界面滚动,但是由于列表复杂,又要使用ListView加载数据,那么就要实现嵌套。
只需要继承ListView并重写以下方法:
// 该自定义控件只是重写了ListView的onMeasure方法,使其不会出现滚动条。
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
然后使用如下嵌套方式即可:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.demo.list.view.MyListView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>