【问题标题】:Android scrolling issue webview inside scrollview with viewpager带有viewpager的滚动视图内的Android滚动问题webview
【发布时间】:2017-01-10 15:04:50
【问题描述】:

我有一个viewpager,其中包含一个布局,其中scrollview 作为父级,webview 作为子级。我从来没有遇到过纵向模式的问题,但是在横向模式下它的表现非常奇怪。

屏幕在横向也采用纵向高度(我假设)。 所以scrollview 在向下滚动时会被激活。

如果我通过输入requestDisallowInterceptTouchEvent(true); 来阻止触摸,但如果我这样做,我将无法移动到下一页。

我在 configChanges 中给出了以下内容

android:configChanges="keyboardHidden|orientation|screenSize"

这是我的主要 xml 代码

<?xml version="1.0" encoding="utf-8"?><ScrollView
android:id="@+id/nestedScrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/topMostLayout">
    <RelativeLayout
        android:id="@+id/topbarlayout"
        android:layout_width="match_parent"
        android:layout_height="43dp"
        android:background="@android:color/white">
    </RelativeLayout>



<View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@android:color/darker_gray"
        android:layout_marginBottom="4dp" />
    <com.mango.expert.utils.FullCard_ShadowLayout
        android:id="@+id/activity_shadow_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:sl_cornerRadius="7dp"
        app:sl_shadowColor="@color/shadow">
        <FrameLayout
            android:id="@+id/dummyLayoutForViewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
<LinearLayout
                android:id="@+id/dummyLinearLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:layout_margin="2dp"
                android:background="@drawable/for_full_card_bg" >
            </LinearLayout>
        </FrameLayout>
    </com.mango.expert.utls.FullCard_ShadowLayout>

<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

</android.support.v4.view.ViewPager>   

缺少一些标签,我发现在这里粘贴 xml 有困难。xml 完全没问题。 任何帮助都会非常棒。忘了提到 webview 在 Fragment 中,而 Scrollview 在主布局中

【问题讨论】:

  • 滚动视图中不需要添加webview
  • 如果我删除滚动视图,我将无法在横向模式下看到全部内容

标签: android webview android-viewpager scrollview orientation


【解决方案1】:

您不需要为 WebView 实现 ScrollView。它本身已经具备该功能。

【讨论】:

  • 我通过删除滚动视图进行了尝试,但我无法在横向模式下看到全部内容,因为它采用横向纵向高度
  • 我认为您没有在 xml 文件中将高度应用为“match_parnet”。
  • ,我给了 match_parent
【解决方案2】:

在父布局上启用 NestedScrolling:

parent.setNestedScrollingEnabled(true);

或将整个布局包装在 NestedScrollView 中:

<android.support.v4.widget.NestedScrollView
        android:id="@+id/nScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <FrameLayout ...>
           <ViewPager ... />
        </FrameLayout >
    </android.support.v4.widget.NestedScrollView>

【讨论】:

  • 感谢您的回答,我会尝试并告诉您
  • 不幸的是没有用,它在纵向模式下也阻止了正常的 webview 滚动
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-26
  • 2013-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多