android scollview嵌套webview底部空白解决方案

    xiaoxiao2021-12-12  2

    废话不多说  直接上代码

    xml布局

    <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:id="@+id/layout_ll_main" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f0f0f0" > <RelativeLayout android:id="@+id/title" style="@style/common_header" > <ImageView android:id="@+id/common_left_back" style="@style/common_header_left_image" /> <TextView style="@style/common_header_center_text" android:text="新闻" /> </RelativeLayout> <LinearLayout android:id="@+id/bottom" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="#dddddd" android:orientation="horizontal" android:paddingTop="2dip" > <LinearLayout android:id="@+id/comment" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_marginLeft="1dip" android:layout_weight="1" android:background="#f5f5f5" android:gravity="center_horizontal" android:orientation="vertical" android:padding="3dip" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3dip" android:adjustViewBounds="true" android:scaleType="centerInside" android:src="@drawable/pinglun01" > </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="评论" android:textColor="#737373" android:textSize="12sp" /> </LinearLayout> <LinearLayout android:id="@+id/shoucang" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_marginLeft="1dip" android:layout_weight="1" android:background="#f5f5f5" android:gravity="center_horizontal" android:orientation="vertical" android:padding="3dip" android:visibility="gone" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3dip" android:adjustViewBounds="true" android:scaleType="centerInside" android:src="@drawable/shoucang01" > </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="收藏" android:textColor="#666" android:textSize="12sp" /> </LinearLayout> <LinearLayout android:id="@+id/fontselect" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_marginLeft="1dip" android:layout_weight="1" android:background="#f5f5f5" android:gravity="center_horizontal" android:orientation="vertical" android:padding="3dip" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3dip" android:adjustViewBounds="true" android:scaleType="centerInside" android:src="@drawable/ziti01" > </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="字体" android:textColor="#737373" android:textSize="12sp" /> </LinearLayout> </LinearLayout> <com.yzs.jzsq.app.utils.MyScrollView android:id="@+id/ScrollView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/bottom" android:layout_below="@+id/title" android:background="#ffffff" android:scrollbars="none" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" > <TextView android:id="@+id/titletext" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="12dip" android:textColor="#000000" android:textSize="20sp" android:visibility="gone" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:orientation="horizontal" android:visibility="gone" > <TextView android:id="@+id/time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:gravity="center" android:textColor="#919191" android:textSize="12sp" /> <TextView android:id="@+id/zuozhe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:gravity="center" android:textColor="#919191" android:textSize="12sp" /> </LinearLayout> <WebView android:id="@+id/mWebView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dip" android:focusable="true" android:focusableInTouchMode="true" /> <LinearLayout android:id="@+id/rela" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#eaeaea" android:gravity="center_vertical" android:orientation="horizontal" > <View android:layout_width="8dip" android:layout_height="35dip" android:background="#3b9ac6" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:text="相关推荐" android:textColor="#8e8e8e" android:textSize="17sp" /> </LinearLayout> <TextView android:id="@+id/xiangguan1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:padding="5dip" android:textColor="#474747" android:textSize="18sp" /> <View android:layout_width="match_parent" android:layout_height="0.8dip" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:background="#cecece" /> <TextView android:id="@+id/xiangguan2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:padding="5dip" android:textColor="#474747" android:textSize="18sp" /> <View android:layout_width="match_parent" android:layout_height="0.8dip" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:background="#cecece" /> <TextView android:id="@+id/xiangguan3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:padding="5dip" android:textColor="#474747" android:textSize="18sp" /> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="end" android:layout_marginTop="5dip" android:background="#ffffff" android:visibility="visible" > <LinearLayout android:id="@+id/titlell" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#eaeaea" android:gravity="center_vertical" android:orientation="horizontal" > <View android:layout_width="6dip" android:layout_height="30dip" android:background="#3b9ac6" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:text="热门评论" android:textColor="#8e8e8e" android:textSize="16sp" /> </LinearLayout> <ListView android:id="@+id/news_comments" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/titlell" android:background="@null" android:cacheColorHint="#00000000" android:divider="#6397b1" android:dividerHeight="1px" android:gravity="center" android:listSelector="#00000000" android:visibility="gone" > </ListView> </RelativeLayout> </LinearLayout> </com.yzs.jzsq.app.utils.MyScrollView> <LinearLayout android:id="@+id/fontsizelyout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/bottom" android:layout_alignParentRight="true" android:orientation="horizontal" android:padding="5dip" android:visibility="gone" > <TextView android:id="@+id/font1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/fontcolor2" android:paddingBottom="4dip" android:paddingLeft="20dip" android:paddingRight="20dip" android:paddingTop="4dip" android:text="小" android:textColor="#000000" /> <TextView android:id="@+id/font2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/fontcolor1" android:paddingBottom="4dip" android:paddingLeft="20dip" android:paddingRight="20dip" android:paddingTop="4dip" android:text="中" android:textColor="#000000" /> <TextView android:id="@+id/font3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/fontcolor2" android:paddingBottom="4dip" android:paddingLeft="20dip" android:paddingRight="20dip" android:paddingTop="4dip" android:text="大" android:textColor="#000000" /> </LinearLayout> </RelativeLayout> </android.support.v4.widget.DrawerLayout>

    代码

    mWebView = (WebView) findViewById(R.id.mWebView); WebSettings webSettings = mWebView.getSettings(); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setAppCacheEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setAllowFileAccess(true); webSettings.setDefaultTextEncodingName("UTF-8"); webSettings.setJavaScriptEnabled(true); webSettings.setBlockNetworkImage(false); webSettings.setRenderPriority(RenderPriority.HIGH); // 设置可以支持缩放 webSettings.setSupportZoom(true); // 设置出现缩放工具 webSettings.setBuiltInZoomControls(true); // Webview自适应屏幕 webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); // Webview自适应屏幕 4.4以下 webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { setWebViewHeight(); super.onPageFinished(view, url); } }); mWebView.addJavascriptInterface(this, "App"); mWebView.loadUrl(job.getString("url")); mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { // 动态在标题栏显示进度条 if (newProgress < 100) showLoading(); else dismiss(); super.onProgressChanged(view, newProgress); } @Override public void onReceivedTitle(WebView view, String temp) { super.onReceivedTitle(view, temp); } }); void setWebViewHeight() { mWebView.loadUrl("javascript:App.resize(Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight))"); } @JavascriptInterface public void resize(final float height) { runOnUiThread(new Runnable() { @Override public void run() { switch (cur_index) { case 0: if (0 != sHeight) mWebView.setLayoutParams(new LinearLayout.LayoutParams( getResources().getDisplayMetrics().widthPixels, sHeight)); else { sHeight = (int) (height * getResources() .getDisplayMetrics().density); mWebView.setLayoutParams(new LinearLayout.LayoutParams( getResources().getDisplayMetrics().widthPixels, sHeight)); } break; case 1: if (0 != nHeight) mWebView.setLayoutParams(new LinearLayout.LayoutParams( getResources().getDisplayMetrics().widthPixels, nHeight)); else { nHeight = (int) (height * getResources() .getDisplayMetrics().density); mWebView.setLayoutParams(new LinearLayout.LayoutParams( getResources().getDisplayMetrics().widthPixels, nHeight)); } break; case 2: if (0 != lHeight) mWebView.setLayoutParams(new LinearLayout.LayoutParams( getResources().getDisplayMetrics().widthPixels, lHeight)); else { lHeight = (int) (height * getResources() .getDisplayMetrics().density); mWebView.setLayoutParams(new LinearLayout.LayoutParams( getResources().getDisplayMetrics().widthPixels, lHeight)); } break; } } }); }

    转载请注明原文地址: https://ju.6miu.com/read-900313.html

    最新回复(0)