【问题标题】:How to scroll the webview in Tab Fragment down如何在 Tab Fragment 中向下滚动 webview
【发布时间】:2017-11-24 06:56:35
【问题描述】:

我的 Webview 是在 Tab Fragment 中实现的。我想将网页视图滚动到片段的底部。现在我无法在片段中向下滚动 webview。我正在使用 android studio 来开发它。以下是我的代码:

片段 XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<WebView
    android:id="@+id/webview"
    android:layout_width="371dp"
    android:layout_height="516dp"
    tools:layout_editor_absoluteX="-12dp"
    tools:layout_editor_absoluteY="-3dp" />
   </android.support.constraint.ConstraintLayout>

活动:

 <android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">
        <TextView
            android:id="@+id/toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:textColor="#ffffff"
            android:layout_gravity="center" />
    </android.support.v7.widget.Toolbar>
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"></android.support.v4.view.ViewPager>

<include layout="@layout/fragment_schedule" />

【问题讨论】:

  • 请回复我,非常感谢
  • 为什么不能滚动?你面临什么错误?任何崩溃?到目前为止你尝试过什么?
  • @Umair,没有崩溃,可以滚动,但不能滚动到底部,意味着它会向下滚动,但不会滚动到网站底部。
  • 你试过用 relativeLayout 代替 constraintLayout 吗?
  • @Umair 我已经解决了,用相对布局替换并在相对布局中添加 android:paddingbottom,谢谢

标签: android xml webview fragment


【解决方案1】:

好吧,尝试使用 RelativeLayout 它将显示完整。由于约束布局,您正面临这个问题:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom= "5dp">

<WebView
android:id="@+id/webview"
android:layout_width="371dp"
android:layout_height="516dp"
tools:layout_editor_absoluteX="-12dp"
tools:layout_editor_absoluteY="-3dp" />
 </RelativeLayout >

【讨论】:

  • 欢迎。你的回答真的对我有帮助,你能在这个问题上帮助我吗?仍然没有反馈。 stackoverflow.com/questions/47407124/…
  • @MollyMolly 兄弟,我没有 IOS 专业知识。但据我了解,您在第二段开始时完成了您的段,如果没有,您必须在背压时实现您的逻辑。同样,这通常是在 android 中发生的。不知道 IOS 可能也是这样。
【解决方案2】:

@Umair 的回答为我指出了正确的方向,但它错过了一点。我不必更改为相对布局来修复它,我的 webview 发出警告,它没有被正确约束(见红色下划线)

在我将宽度和高度更改为

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    tools:layout_editor_absoluteY="1dp" />

问题立即得到解决。现在这个问题可能只出现在片段中,但这是解决它的一种方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    • 2015-04-30
    • 2016-05-16
    • 2017-02-24
    • 2017-11-24
    • 2020-12-13
    • 1970-01-01
    相关资源
    最近更新 更多