webView 收起和展开

收起效果

private MyWebViewHeightListener onMyWebViewHeightListener = null;

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (onMyWebViewHeightListener != null) {
            onMyWebViewHeightListener.onMyWebViewHeightListener(getContentHeight());
            onMyWebViewHeightListener = null;
        }
    }

    public void setOnMyWebViewHeightListener(MyWebView.MyWebViewHeightListener onMyWebViewHeightListener) {
        this.onMyWebViewHeightListener = onMyWebViewHeightListener;
    }

    /**
     * 监听内容高度
     */
    public interface MyWebViewHeightListener {
        void onMyWebViewHeightListener(int minHeight);
    }

这里通过监听webView高度,在调用控件时可以判断超过所设高度,然后设置你希望的高度
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(MATCH_PARENT, 500);
mWebEssayfragmentHeaderContent.setLayoutParams(lp);

展开效果

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT);
                mWebEssayfragmentHeaderContent.setLayoutParams(lp);

你可能感兴趣的:(Android,技术,webview)