我正在构建一个包含输入表单和 WebView 的应用程序。 该项目可在 http://code.google.com/p/android-sap-note-viewer/ 获得。
WebView 将根据输入呈现一个网站,该页面有一个包含主要内容(可能有数百行)的 DIV。我无法控制网站上的内容。
Android WebKit 似乎没有在 DIV 中进行任何滚动,引用 http://www.gregbugaj.com/?p=147 .因此,只有部分 DIV 显示给用户,无法检索其余文本。 我的挑战是找到一种显示 DIV 的所有文本的方式。
我的观点定义如下:
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
android:text="@string/lblNote" />
<EditText android:id="@+id/txtNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:numeric="decimal"
android:maxLength="10"
/>
<Button android:id="@+id/bView"
android:text="@string/bView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:keepScreenOn="false"
android:minHeight="4096px"
/>
</LinearLayout>
在这里,我尝试将 WebView 硬编码到一个较大的高度,以确保 DIV 被拉伸(stretch)并显示所有文本,并强制 LinearLayout 进行滚动。
但是,WebView 始终会适应屏幕尺寸(这在大多数情况下会很好,但不是这种情况)。
关于如何解决这个问题有什么想法吗?
(我现在看到的唯一解决方案是自己获取 HTML,删除 DIV 并将其发送到 WebView)
最佳答案
我想你想为此使用权重。我对你的 xml 代码有点困惑,因为你有一个额外的 LinearLayout 标签,但我认为你正在寻找这样的东西:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android: orientation="vertical">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
android:text="@string/lblNote" />
<EditText android:id="@+id/txtNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:numeric="decimal"
android:maxLength="10"
/>
<Button android:id="@+id/bView"
android:text="@string/bView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
</LinearLayout>
这里 Webview 将填充内部 LinearLayout 不使用的屏幕的其余部分,因为只有 webview 具有 weight 属性。希望这会有所帮助。
关于Android:强制 WebView 达到一定高度(或触发 div 的滚动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2271532/