webView 收起和展开

xiaoxiao2021-02-28  8

收起效果

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);
转载请注明原文地址: https://www.6miu.com/read-1150132.html

最新回复(0)