解决:ScrollView中嵌套ListView无法正常显示

来源:互联网 发布:数据整合的方法 编辑:程序博客网 时间:2024/06/06 08:53
这个方法和上面的方法是异曲同工,方法3是自定义了LinearLayout以取代ListView的功能,但如果我脾气就是倔,就是要用ListView怎么办?那就只好自定义一个类继承自ListView,通过重写其onMeasure方法,达到对ScrollView适配的效果。</span>

package com.example.xxxx;import android.content.Context;import android.util.AttributeSet;import android.widget.ListView;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 defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        int height = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);        super.onMeasure(widthMeasureSpec, height);    }}
0 0
原创粉丝点击