【问题标题】:Swiperefresh layout not working in coordinate layout inside nested scrollviewSwiperefreshlayout 在嵌套滚动视图内的协调器布局中不起作用
【发布时间】:2020-06-30 05:33:09
【问题描述】:

我想在向下滚动时隐藏工具栏,所以我使用坐标布局,我需要使用 webview 的布局。 当我在nestedscrollview 中使用swiperefreshlayout 时,我的webview 不会出现。 我该如何解决这个问题?

这是布局文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
    tools:context=".WebActivity">


    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </com.google.android.material.appbar.AppBarLayout>


    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swipe_refresh_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <WebView
                android:id="@+id/wv"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />


        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    </androidx.core.widget.NestedScrollView>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

【问题讨论】:

    标签: android xml android-studio android-coordinatorlayout swiperefreshlayout


    【解决方案1】:

    你显然需要在NestedScrollView之外使用SwipeRefreshLayout

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
        <androidx.core.widget.NestedScrollView
            android:id="@+id/swipe_refresh_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    

    另外,请注意在NestedScrollView 中使用WebView,如果不添加它们可能无法正常工作:

    android:nestedScrollingEnabled="true"
    

    WebView。此外,将WebViewandroid:layout_height 设置为wrap_content,然后它应该可以按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 2017-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-14
      相关资源
      最近更新 更多