Calculate the size of a list view or how to tell it to fully expand

前端 未结 12 966
小蘑菇
小蘑菇 2020-11-29 00:20

I am currently trying to use a ListView inside of a ScrollView. I know from what I\'ve read that this is looked down upon, but I\'m trying to get the ListView to expand com

12条回答
  •  庸人自扰
    2020-11-29 00:59

    use this will be worked:

    public class ListViewEx extends ListView {
    
    public ListViewEx(Context context) {
        super(context);
    }
    
    /**
     * @param context
     * @param attrs
     */
    public ListViewEx(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    /**
     * 设置不滚动
     */
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
    
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return ev.getAction()==MotionEvent.ACTION_MOVE||super.dispatchTouchEvent(ev);
    }
    

    }

提交回复
热议问题