<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:descendantFocusability="blocksDescendants"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.xxxx.NoWrapListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<WebView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
android:descendantFocusability="blocksDescendants"
inner class XWalkWebClient : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
isPageLoadSuccess = true
}
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
view?.loadUrl("javascript:window.myapp.resize(document.body.getBoundingClientRect().bottom);") //此处调用了一个注入的js方法用来重载webview高度,可解决初始加载网页的问题,①
}
}
webBrowser?.addJavascriptInterface(MyAppJavascriptHandler(), "myapp")
inner class MyAppJavascriptHandler {
@JavascriptInterface
fun resize(documentBodyHeight: Int) {
if (isAllowReLayoutBrowser) {
(context as? Activity?)?.runOnUiThread {
ViewUtil.setViewLayoutParams<FrameLayout.LayoutParams>(webBrowser!!, {
it.width = context.resources.displayMetrics.widthPixels
it.height = (documentBodyHeight * context.resources.displayMetrics.density).toInt()
}) //重写webview的高度, ②
}
}
}
}
if(window.myapp.resize){
window.myapp.resize(document.body.getBoundingClientRect().bottom);
}
/**
* 配置控件的布局属性
* @param view
* @param func 处理布局属性的回调方法
*/
@Suppress("unchecked_cast")
@JvmStatic
fun <T : ViewGroup.LayoutParams> setViewLayoutParams(view: View, func: (T) -> Unit) = with(this) {
val lp: T = view.layoutParams as T
func.invoke(lp)
view.layoutParams = lp
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有