android WebView设置最大高度
2016-08-01 17:12
591 查看
当我们在dialog中嵌入webview来显示网页信息时,如果网页内容足够长,则会出现dialog高度被撑满屏,但是介于美观问题,我们会试图动态设置webview的最大高度,可是遗憾的是,谷歌并没有给我们提供这个方法,聪明人想出了聪明的办法,具体请看下面代码:
友情提示:设置最大高度一定要在加载内容之前!!!
转自:http://blog.csdn.net/handerhuo/article/details/48003625
public class MyWebView extends WebView { private int mMaxHeight = -1; public MyWebView(Context context) { super(context); // TODO Auto-generated constructor stub } public MyWebView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public MyWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public MyWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { super(context, attrs, defStyle, privateBrowsing); // TODO Auto-generated constructor stub } public void setMaxHeight(int height){ mMaxHeight = height; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(mMaxHeight>-1 && getMeasuredHeight()>mMaxHeight){ setMeasuredDimension(getMeasuredWidth(), mMaxHeight); } } }结果,世界和平了
友情提示:设置最大高度一定要在加载内容之前!!!
转自:http://blog.csdn.net/handerhuo/article/details/48003625
相关文章推荐
- android WebView设置最大高度
- Android之WebView——解决加载Https以及根据网页动态设置WebView高度等难题
- android 获取webView高度,设置webView高度
- WebView设置最大高度
- android 设置webview的高度,解决网页高度过小头部空白问题
- android 下的webview 设置多点触控放大
- android webview 设置背景透明色
- android webview的 一些设置(js java交互)
- android webview 设置背景透明色
- android WebView缩放设置setInitialScale(...)后,修改设置的值,问题解决
- android webview的一些设置问题
- android webview透明设置
- 转 android 下的webview 设置多点触控放大
- android ScrollView 中子控件设置高度后不起作用的解决方法
- android webview设置背景固定不动
- Android webview背景设置为透明无效
- 设置android WebView 不显示滚动条
- Android webview背景设置为透明无效
- android webview 4.0设置背景透明
- Android 2.3 WebView 表格设置字体