問題描述:
在#關於#模塊,點擊電源按鍵,讓屏幕休眠,然後再點擊電源按鍵,喚醒屏幕,解鎖,回到#關於#模塊,#關於內容#view高度自動增高爲原來的兩倍。
程序打印出來的日誌:
11-25 10:19:58.116: @onLayoutChange. webView's layout-info. 11-25 10:19:58.116: @onLayoutChange. oldLeft:13, oldRight:908, oldTop:13, oldBottom:332 11-25 10:19:58.116: @onLayoutChange. left:13, right:908, top:13, bottom:211 11-25 10:19:58.116: @onLayoutChange. rlContent's layout-info. 11-25 10:19:58.116: @onLayoutChange. oldLeft:67, oldRight:988, oldTop:306, oldBottom:651 11-25 10:19:58.116: @onLayoutChange. left:67, right:988, top:306, bottom:530 11-25 10:21:13.096: @onLayoutChange. webView's layout-info. 11-25 10:21:13.096: @onLayoutChange. oldLeft:13, oldRight:908, oldTop:13, oldBottom:211 11-25 10:21:13.096: @onLayoutChange. left:13, right:428, top:13, bottom:211 11-25 10:21:13.096: @onLayoutChange. rlContent's layout-info. 11-25 10:21:13.096: @onLayoutChange. oldLeft:67, oldRight:988, oldTop:306, oldBottom:530 11-25 10:21:13.096: @onLayoutChange. left:67, right:508, top:306, bottom:530 11-25 10:21:13.256: @onLayoutChange. webView's layout-info. 11-25 10:21:13.256: @onLayoutChange. oldLeft:13, oldRight:428, oldTop:13, oldBottom:211 11-25 10:21:13.256: @onLayoutChange. left:13, right:428, top:13, bottom:388 11-25 10:21:13.256: @onLayoutChange. rlContent's layout-info. 11-25 10:21:13.256: @onLayoutChange. oldLeft:67, oldRight:508, oldTop:306, oldBottom:530 11-25 10:21:13.256: @onLayoutChange. left:67, right:508, top:306, bottom:707 11-25 10:21:13.336: @onLayoutChange. webView's layout-info. 11-25 10:21:13.336: @onLayoutChange. oldLeft:13, oldRight:428, oldTop:13, oldBottom:388 11-25 10:21:13.336: @onLayoutChange. left:13, right:908, top:13, bottom:388 11-25 10:21:13.336: @onLayoutChange. rlContent's layout-info. 11-25 10:21:13.336: @onLayoutChange. oldLeft:67, oldRight:508, oldTop:306, oldBottom:707 11-25 10:21:13.336: @onLayoutChange. left:67, right:988, top:306, bottom:707 11-25 10:21:13.456: @onLayoutChange. webView's layout-info. 11-25 10:21:13.456: @onLayoutChange. oldLeft:13, oldRight:908, oldTop:13, oldBottom:388 11-25 10:21:13.456: @onLayoutChange. left:13, right:908, top:13, bottom:388 11-25 10:21:13.456: @onLayoutChange. rlContent's layout-info. 11-25 10:21:13.456: @onLayoutChange. oldLeft:67, oldRight:988, oldTop:306, oldBottom:707 11-25 10:21:13.456: @onLayoutChange. left:67, right:988, top:306, bottom:707 11-25 10:21:13.516: @onLayoutChange. webView's layout-info. 11-25 10:21:13.516: @onLayoutChange. oldLeft:13, oldRight:908, oldTop:13, oldBottom:388 11-25 10:21:13.516: @onLayoutChange. left:13, right:908, top:13, bottom:388 11-25 10:21:13.516: @onLayoutChange. rlContent's layout-info. 11-25 10:21:13.516: @onLayoutChange. oldLeft:67, oldRight:988, oldTop:306, oldBottom:707 11-25 10:21:13.516: @onLayoutChange. left:67, right:988, top:306, bottom:707
WebView實現說明:
1.通過findViewById獲取WebView。
webview = (WebView) view.findViewById(R.id.content);
2.設置webView的默認編碼方式。
webview.getSettings().setDefaultTextEncodingName("utf-8");
3.調用loadDataWithBaseURL方法加載數據。(loadData會出現亂碼)
webview.loadDataWithBaseURL(null, data.getContent(), "text/html", "utf-8", null);
4.在佈局文件中定義
<WebView android:id="@+id/content" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@null" android:padding="0dp" />
查找很久沒有發現這個問題如何解決,還是換一種實現方法(使用TextView來替換WebView)
content = (TextView) view.findViewById(R.id.content); ... content.setText(Html.fromHtml(data.getContent()));
參考資料:
1. Android WebView 顯示的內容高度獲取
http://hi.baidu.com/guoxiaoming/item/bb1ca1da8b46192938f6f771
2.Android WebView常見問題及解決方案彙總
http://blog.csdn.net/t12x3456/article/details/13769731
3.Android的TextView與Html結合用法
http://www.3lian.com/edu/2012/11-24/46045.html