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);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
自定义了ListView,在ScrollView中总是置顶显示,不管ListView上面是否有其它view。
解决一:
手动设置ScrollView:
ScrollView s = (ScrollView) view.findViewById(R.id.scrollView);
s.smoothScrollTo(0, 0);
解决二:无需手动设置
在ScrollView中需要置顶控件添加以下属性
android:focusableInTouchMode="true"
android:focusable="true"