2

我想要:

  1. 在屏幕上放置一个片段,其中包含:
    1. 一个网页视图
    2. ...扩展至全高
    3. 嵌入在上下固定大小的布局中
    4. 滚动布局(即整个内容,包括全高 webview)

这似乎是不可能的。我现在已经阅读了 10 多个关于 SO 的不同问题/答案,所有这些都涵盖了 Android WebView 中不同的关键错误,但没有一个涵盖这种情况。

似乎(通过阅读其他问题,并在 android 网站上关注当前未修复错误的链接):

  1. WebView 的高度一直是错误的(未修复的 Android 2 - 4:例如高度从不降低)
  2. WebView 的滚动中断、取消中断、在连续的 Android 版本中以新的方式重新中断(例如:某些版本 ScrollView 获得控制权,其他 WebView 获得控制权,其他他们“战斗”并且你会结结巴巴等)
  3. 您必须对 ScrollView 进行一些奇怪的调整,以使其能够做到开箱即用。例如“android:fillViewport="true"(嗯?这不正是“layout_height=fill_parent”应该做的吗?)

有没有人有工作代码来实现这个相对简单和常见的设置?我会对任何有效的东西感兴趣(当然除了“扔掉你的 Android 应用程序并编写一个 web 应用程序”。这可能有效,但很遗憾,这是不切实际的)

供参考(以及其他尝试类似操作的人)这是我的布局,它填满了屏幕,但所有滚动都被禁用,我无缘无故地看到:

<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>
4

2 回答 2

5

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

在此处输入图像描述

请尝试使用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;
    }


}
于 2013-05-08T21:07:00.740 回答
1

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

请记住“Web”可以TextView代替WebView,请记住“滚动”可以ListView代替ScrollView,并且请记住“自定义页眉/页脚组合”可以在WebView. 其中任何一个都可以让您摆脱WebView困境ScrollView。很少有应用ScrollViewWebView使用ScrollView.

当然还有更复杂的可能性。例如,Gmail 的对话视图是一个WebView在 Z 轴上使用 a 在其顶部分层的其他事物FrameLayout,它们可能跟踪 的滚动事件WebView以更改在其顶部分层的其他事物的位置(例如,固定发件人- and-reply-button 标题,当您滚动到顶部时)。

如果您有 Android 4.1+ 设备,欢迎您使用uiautomatorviewer来了解如何实现这类东西。这就是我看到 Gmail 是如何成功的。你无法获得所有细节,但它会为你提供线索。

于 2013-05-08T21:53:34.670 回答