ListView嵌套在ScrollView中,只显示一行的解决办法

来源:互联网 发布:淘宝怎么赚运费险 编辑:程序博客网 时间:2024/05/16 15:05

自定义一个ListView,在onMeasure方法里对其的高度进行重新设置
然后在xml里将listview改成这个就行,java代码都可以不用改

import android.content.Context;import android.util.AttributeSet;import android.widget.ListView;/** * Created by wt on 2017/2/21. */public class ListScrollView extends ListView {    public ListScrollView (Context context) {        super(context);    }    public ListScrollView (Context context, AttributeSet attrs) {        super(context, attrs);    }    public ListScrollView (Context context, AttributeSet attrs,                                 int defStyle) {        super(context, attrs, defStyle);    }    @Override    /**     * 重写该方法,达到使ListView适应ScrollView的效果     */    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,                MeasureSpec.AT_MOST);        super.onMeasure(widthMeasureSpec, expandSpec);    }}
0 0
原创粉丝点击