ScrollView中的WebView可防止所有滚动

时间:2013-05-08 20:05:54

标签: android webview

我想:

  1. 在屏幕上放置一个片段,其中包含:
    1. 一个WebView
    2. ......扩展到全高
    3. 嵌入在上下固定大小的布局中
    4. 滚动布局(即整个内容,包括全高webview)
  2. 这似乎不可能。我现在已经在SO上阅读了10多个不同的问题/答案,它们都涵盖了Android WebView中的不同关键错误,但它们都没有涵盖这种情况。

    似乎(从阅读其他问题,并链接到Android网站上当前未修复的错误):

    1. WebView的高度一直是错误的(未修复的Android 2 - 4:例如高度永远不会减少)
    2. WebView的滚动中断,不间断,在连续的Android版本中以新的方式重新中断(例如:一些版本ScrollView控制,其他WebView控制,其他人“战斗”,你得到口吃等)
    3. 你必须对ScrollView进行一些奇怪的调整,使它能够做到开箱即用的功能。例如“android:fillViewport =”true“(嗯?这究竟不是”layout_height = fill_parent“应该做什么的?)
    4. 有没有人有工作代码来实现这种相对简单和常见的设置?我会对任何有用的东西感兴趣(当然除了“扔掉你的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 -->
      
                  <include
                      android:id="@+id/fragment_detailspage_bottombuttonstrip1_include"
                      android:layout_width="wrap_content"
                      android:layout_height="64dp"
                      android:layout_centerHorizontal="true"
                      layout="@layout/include_bottombuttonstrip1" />
              </RelativeLayout>
      
              <!-- page content -->
      
              <WebView
                  android:id="@+id/fragment_detailspage_content_web"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_above="@id/fragment_detailspage_footer_layout"
                  android:layout_below="@id/fragment_detailspage_header_layout"
                  android:visibility="visible" />
      
          </RelativeLayout>
      
      </ScrollView>
      

2 个答案:

答案 0 :(得分:5)

对不起下面的图片,但我想象每次,当有人想在可滚动视图中放置可滚动视图时。

enter image description here

请尝试使用 CustomScrollView 并覆盖 onInterceptTouchEvent

public class CustomScrollView extends ScrollView {

    public CustomScrollView(Context context) {
        super(context);
    }

    public CustomScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent e) {
        super.onInterceptTouchEvent(e);
        return false;
    }


}

答案 1 :(得分:1)

  

我使用的应用程序几乎都有某种形式的Web / Scroll /自定义页眉/页脚组合

请记住&#34; Web&#34;可以是TextView而不是WebView,请记住&#34; Scroll&#34;可以是ListView而不是ScrollView,请记住&#34;自定义页眉/页脚组合&#34;可以在WebView内的HTML中实现。任何这些都可以让您摆脱WebView - in - a - ScrollView场景。很少有应用会使用ScrollView,而WebView中仍会有更少的用户尝试使用ScrollView

肯定有更复杂的可能性。例如,Gmail的对话视图是WebView,其他内容使用FrameLayout在Z轴上分层,其中可能会跟踪WebView的滚动事件更改分层顶部的其他内容的位置(例如,在滚动时将发件人和回复按钮标头固定到顶部)。

如果您使用的是Android 4.1及更高版本的设备,欢迎使用 uiautomatorviewer 来了解如何实施此类内容。这就是我如何看待Gmail如何实现这一目标的方式。你无法获得所有细节,但它可以为你提供线索。