【问题标题】:Android: Webview is not scrolling with the content of pageAndroid:Webview 不随页面内容滚动
【发布时间】:2015-12-14 11:48:59
【问题描述】:

我在我的布局中使用 webview,它占据了屏幕的上半部分。 数据的其他内容正在向下半屏显示。 数据量很大,因此滚动即将到来,但问题只是下半部分正在滚动,而创建 webview 的上半部分没有滚动。 我想将该 webview 粘贴到屏幕顶部,这样它也会滚动并滚动我可以全屏查看新数据。

我的布局代码:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/navMainLayout">

<ImageButton
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:src="@drawable/right_menu"
    android:id="@+id/drawerClickBtn"
    android:padding="2dp"
    android:background="@android:color/white"
    android:scaleType="fitXY"/>
    <View
        android:layout_width="40dp"
        android:layout_height="120dp"
        android:background="@android:color/white"
        android:layout_below="@+id/drawerClickBtn" />
    <WebView
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:id="@+id/qblebelId"
        android:gravity="center|left"
        android:layout_toRightOf="@+id/drawerClickBtn"
        android:layout_alignBaseline="@+id/drawerClickBtn"
        android:textColor="@color/AppThemeColor"
        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
        android:text="Question Bank"/>

    <ListView
        android:id="@+id/expertAnswerlistId"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:padding="10dp"
        android:animationCache="false"
        android:cacheColorHint="@android:color/transparent"
        android:layout_below="@+id/qblebelId"
        android:divider="@null"
        android:dividerHeight="10dp"
        android:listSelector="@android:color/transparent"
        android:scrollingCache="false"
        android:fadeScrollbars="false"
        android:smoothScrollbar="true"
        android:longClickable="false"
        android:scrollbars="none"
        android:descendantFocusability="blocksDescendants" />

</RelativeLayout>

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<LinearLayout
    android:id="@+id/navDrawerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <include
        android:id="@+id/toolbar"
        layout="@layout/tool_bar_expand"/>

    <ExpandableListView
        android:id="@+id/nav_left_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:longClickable="false"
        android:groupIndicator="@null" >
    </ExpandableListView>
</LinearLayout>

【问题讨论】:

  • 如果你有困惑,问我。我可以提供更多细节。
  • 我看不到任何一半的网页视图。请解释清楚
  • 我给出了 webview 的高度,因为它出现在屏幕的一半上。

标签: android xml webview


【解决方案1】:

这可能对你有帮助:

WebView v = (WebView) findViewById(R.id.webview); 
v.setVerticalScrollBarEnabled(true);
v.setHorizontalScrollBarEnabled(true);

【讨论】:

  • 这提供了 webview 内部的滚动,但我想要在 webview 之外。完整版面。
【解决方案2】:

使用

android:layout_width="wrap_content"
android:layout_height="wrap_content"

而不是

android:layout_width="match_parent"
android:layout_height="160dp"

【讨论】:

  • 好的,我正在尝试。
  • 同样的问题,Webview 不与屏幕的其他内容一起滚动。
【解决方案3】:

可能会帮助您尝试一下

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:id="@+id/navMainLayout"
  xmlns:android="http://schemas.android.com/apk/res/android">

 <ImageButton
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:src="@drawable/right_menu"
    android:id="@+id/drawerClickBtn"
    android:padding="2dp"
    android:background="@android:color/white"
    android:scaleType="fitXY"/>
<View
    android:layout_width="40dp"
    android:layout_height="120dp"
    android:background="@android:color/white"
    android:layout_below="@+id/drawerClickBtn" />
<WebView
    android:layout_width="match_parent"
    android:layout_height="160dp"
    android:id="@+id/qblebelId"
    android:gravity="center|left"
    android:layout_toRightOf="@+id/drawerClickBtn"
    android:layout_alignBaseline="@+id/drawerClickBtn"
    android:textColor="@color/AppThemeColor"
    android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
    android:text="Question Bank"/>

<ListView
    android:id="@+id/expertAnswerlistId"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="10dp"
    android:padding="10dp"
    android:animationCache="false"
    android:cacheColorHint="@android:color/transparent"
    android:layout_below="@+id/qblebelId"
    android:divider="@null"
    android:dividerHeight="10dp"
    android:listSelector="@android:color/transparent"
    android:scrollingCache="false"
    android:fadeScrollbars="false"
    android:smoothScrollbar="true"
    android:longClickable="false"
    android:scrollbars="none"
    android:descendantFocusability="blocksDescendants" />



  <FrameLayout
   android:id="@+id/content_frame"
   android:layout_width="match_parent"
   android:layout_height="match_parent" />

  <LinearLayout
   android:id="@+id/navDrawerView"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_gravity="start"
   android:background="@android:color/white"
   android:orientation="vertical" >

   <include
     android:id="@+id/toolbar"
     layout="@layout/tool_bar_expand"/>

   <ExpandableListView
    android:id="@+id/nav_left_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:longClickable="false"
    android:groupIndicator="@null" >
   </ExpandableListView>
   </LinearLayout>
   </RelativeLayout>

【讨论】:

  • 我看不到任何变化。你在这段代码中修改了什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-17
相关资源
最近更新 更多