我必须将WebView放入ScrollView.但是我必须在webview之前将一些视图放到同一个scrollview中.所以它看起来像这样:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/articleDetailPageContentLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/articleDetailRubricLine"
android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="@color/fashion"/>
<ImageView
android:id="@+id/articleDetailImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="@drawable/article_detail_image_test"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:text="PUBLISH DATE"/>
<WebView
android:id="@+id/articleDetailContentView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/fashion"
android:isScrollContainer="false"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我从后端获得了一些HTML信息.它没有任何身体或头部标签,只有被<p>或<h4>或其他标签包围的数据.它还有<img>标签.有时图片对于当前屏幕宽度来说太宽.所以我在HTML的开头添加了一些CSS.所以我将数据加载到webview,如下所示:
private final static String WEBVIEW_MIME_TYPE = "text/html";
private final static String WEBVIEW_ENCODING = "utf-8";
String viewport = "<head><meta name=\"viewport\" content=\"target-densitydpi=device-dpi\" /></head>";
String css = "<style type=\"text/css\">" +
"img {width: 100%;}" +
"</style>";
articleContent.loadDataWithBaseURL("http://", viewport + css + articleDetail.getContent(), …Run Code Online (Sandbox Code Playgroud) 我想在ScrollView中使用WebView作为我的本机应用程序.但是如果我这样做,我就无法滚动我的webview,除非我在scrollview上禁用滚动.但是,我需要scrollview和webview中的滚动.有关如何完成此任务的任何建议或解决方案?
webview react-native react-native-scrollview react-native-android
我有一个用于测试目的的网页(https://storage.googleapis.com/htmltestingbucket/nested_scroll_helper.html),它只打印html在固定标题中捕获的滚动事件的计数器
当Android WebView是片段中唯一可滚动的元素时,一切都很好,WebView将滚动事件发送到页面
如果我想在WebView的上方和下方添加原生元素,那么事情会变得复杂得多.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="SOMETHING ABOVE THE WEBVIEW" />
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="SOMETHING BELOW THE WEBVIEW" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我知道在ScrollView中使用WebView并不好,但我必须在html文档中提供混合内容和正确滚动事件的单一滚动体验.我发现了很多关于此事的问题,但我能够创建一个完整的端到端解决方案
此外,我知道lint有一个官方的检查:
NestedScrolling ---------------摘要:嵌套滚动小部件
优先级:7/10严重性:警告类别:正确性
滚动窗口小部件(如ScrollView)不应包含任何嵌套滚动窗口小部件,因为它具有各种可用性问题
然而,我无法在本机中实现Web视图内容,因此我需要另一种方法来实现
我有一个WebView用于加载Web内容的活动.当我想用图像实现Flexible Space时会出现问题.我可以扩展和折叠Toolbar,但当Toolbar已经折叠时,滚动条卡在那里.我无法滚动里面的内容WebView.
这是XML:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<WebView
android:id="@+id/read_full_content_wv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
你对此有什么解决方案吗?
此致,埃尔默
编辑 后我查看LinX64给出的链接.我试着添加:
public class FullContentActivity extends AppCompatActivity {
...
@Override
protected void onCreate(Bundle savedInstance){
...
WebView webView = (WebView) findViewById(R.id.read_full_content_wv);
webView.setWebViewClient(new MyBrowser());
webView.loadData(extra.get(1).toString(), "text/html", "utf-8");
...
}
...
private class MyBrowser extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
NestedScrollView nsv = (NestedScrollView) findViewById(R.id.nsv_fc);
nsv.scrollTo(0,0);
}
}
}
Run Code Online (Sandbox Code Playgroud)
并且仍然被困住了.
EDIT 2 FYI:我试过华硕Zenfone …
使用WebView内部时NestedScrollView有一些问题.我正在争取的主要是那些在向下滚动时加载更多内容的网站效果不佳,例如vimeo.com.同样设置视图LAYER_TYPE_HARDWARE不起作用,可能出于同样的原因,它基本上因高度而崩溃.那么,有没有到一个替代NestedScrollView,如果我想使用CoordinatorLayout,以折叠工具栏时,里面的用户滚动WebView?
我的代码如下.要重现此问题,只需加载vimeo.com并滚动到底部即可.
activity_scrolling.xml
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.webviewnestedscroll.ScrollingActivity"
tools:showIn="@layout/activity_scrolling">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
ScrollingActivity.java
package com.webviewnestedscroll;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings; …Run Code Online (Sandbox Code Playgroud) android webview android-webview android-support-library android-design-library
我想要:
这似乎不可能.我现在已经在SO上阅读了10多个不同的问题/答案,所有这些都涵盖了Android WebView中的不同关键错误,但它们都没有涵盖这种情况.
似乎(从阅读其他问题,并链接到Android站点上当前未修复的错误):
有没有人有工作代码来实现这个相对简单和常见的设置?我会对任何有用的东西感兴趣(当然除了"扔掉你的Android应用程序并编写一个webapp".这可能有效,但遗憾的是不切实际)
作为参考(和任何其他尝试类似的东西)这里是我的布局,填充屏幕,但所有滚动都被禁用,无缘无故我可以看到:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- page header -->
<RelativeLayout
android:id="@+id/fragment_detailspage_titletext_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:visibility="visible" >
<include
android:id="@+id/fragment_detailspage_titletext_include"
layout="@layout/include_textheader"
android:visibility="visible" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/fragment_detailspage_header_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/fragment_detailspage_titletext_layout"
android:clickable="true"
android:visibility="visible" >
<!-- logo image -->
<include
android:id="@+id/fragment_detailspage_logoimageheader_include"
layout="@layout/include_logoimageheader" />
</RelativeLayout>
<!-- page footer -->
<RelativeLayout
android:id="@+id/fragment_detailspage_footer_layout"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:layout_alignParentBottom="true"
android:background="@drawable/generic_button_not_pressed"
android:clickable="true"
android:visibility="visible" >
<!-- 1 buttons --> …Run Code Online (Sandbox Code Playgroud) 这是我的XML布局中的一个浮动操作按钮。
我在NestedScrollView中的Webview导致收缩缩放支持崩溃。
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@drawable/filter_icon"
android:tint="#FFFFFF"
app:backgroundTint="@color/colorPrimary"
app:elevation="4dp"
app:fabSize="normal"
app:useCompatPadding="true"
app:layout_anchorGravity="bottom|end|right"
app:layout_behavior=".ScrollAwareFABBehavior">
</android.support.design.widget.FloatingActionButton>
Run Code Online (Sandbox Code Playgroud)