【发布时间】:2013-05-08 20:05:53
【问题描述】:
我想:
- 在屏幕上放置一个片段,其中包含:
- 一个 Web 视图
- ...展开到全高
- 嵌入在上下固定大小的布局中
- 滚动布局(即整个内容,包括全高 web 视图)
这似乎是不可能的。我现在已经阅读了 10 多个关于 SO 的不同问题/答案,它们都涵盖了 Android WebView 中不同的严重错误,但没有一个涵盖这种情况。
似乎(通过阅读其他问题,并通过链接指向 android 网站上当前未修复的错误):
- WebView 的高度一直是错误的(Android 2 - 4 未修复:例如高度从不降低)
- WebView 的滚动中断、取消中断、重新中断在连续的 Android 版本中以新的方式(例如:某些版本 ScrollView 获得控制权,其他 WebView 获得控制权,其他他们“打架”并且您会卡顿等)
- 您必须对 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>
【问题讨论】:
-
你看过这篇文章了吗? stackoverflow.com/a/13353874/801437
-
“我现在已经阅读了 10 多个关于 SO 的不同问题/答案,它们都涵盖了 Android WebView 中不同的严重错误,但没有一个涵盖这种情况”——我很确定我已经回答了很多 Android 问题,表明将可滚动内容放在
ScrollView中效果不佳。 -
+1 关于 CommonsWare 的观点,不要将可滚动视图放在 ScrollView 中。您的布局看起来可能有点......过度设计。您可以将图像附加到您希望布局看起来的 Q 上,然后也许我们可以帮助您简化 xml 并解释为什么您不需要 ScrollView 中的 WebView
-
@VishalVyas 是的,我看到了那个。它使 webview 滚动,但禁用滚动视图。我正在尝试做相反的事情(从 Android 文档来看,这似乎是 INTENDED 默认值)
-
@CommonsWare - 是的,我同意它效果不佳,这是一个糟糕的课程。但它几乎被所有应用程序使用(和滥用),所以......我认为必须有一些体面的解决方法:)。也许有一个社区创作的 BetterScrollView 或类似的(我还没有找到:()等。