【发布时间】:2016-02-14 19:06:23
【问题描述】:
这是我的布局。当我加载 google.com 时,webview 的高度会无限增长。 webview 的 onSizeChange 函数不断被调用,我可以看到 webview 不断扩展。我已经尝试了 design 和 appcompat 库的 22.2.1 和 23.1.0 并且没有效果。
有什么解决办法吗? :-|
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.example.ajay.scrollabletoolbar.MyWebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"/>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<android.support.v7.widget.Toolbar
android:id="@+id/restricted_browser_toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true">
<EditText
android:id="@+id/current_url"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:backgroundTint="@android:color/darker_gray"
android:dropDownAnchor="@+id/restricted_browser_toolbar"
android:hint="hint hint"
android:imeOptions="actionGo|flagNoExtractUi"
android:inputType="textNoSuggestions|textUri"
android:paddingBottom="8dp"
android:paddingEnd="8dp"
android:paddingStart="8dp"
android:singleLine="true"/>
<ImageView
android:id="@+id/clear_url_text"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignRight="@+id/current_url"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:src="@android:drawable/ic_menu_close_clear_cancel"
android:visibility="gone"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
【问题讨论】:
-
我认为我不能使用固定尺寸。我希望 webview 在所有手机和平板电脑中占据整个窗口。
-
当然可以,就像将窗口大小设置为webview一样简单,为什么你认为你不能?
-
我尝试将其设置为固定大小。硬编码和窗口大小。问题是 webview 不滚动。如果我有一个像 800dp 这样的硬编码值,webview 会显示一个网页更新 800dp 并在它之后剪掉这些东西。所以我无法看到它下面的部分。我根据不同的 SO 帖子尝试了类似的事情并且遇到了同样的问题。 Webview 不会加载超出设置大小的网页。我认为应该有一个更清洁的解决方案
-
webview 应该有自己的滚动条,应该像 firefox 一样,如果网页大于它应该有滚动条的窗口...你试过这个:setVerticalScrollBarEnabled(true);?
-
已启用。如果我删除了nestedScrollView,webview 按预期工作并且滚动工作
标签: android webview android-coordinatorlayout android-collapsingtoolbarlayout nestedscrollview