ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Webview는 무한 스크롤 가능 공백을 유발합니다.
    카테고리 없음 2020. 8. 12. 10:31

    질문

    NestedScrollview 내부에 Webview가 포함 된 레이아웃이 있습니다.

    <?xml version="1.0" encoding="utf-8"?>
    <com.app.swipetofinish.SwipeDownLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/postContainer"
    android:descendantFocusability="blocksDescendants"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/postDetails"
            android:background="?attr/backgroundColor">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:scaleType="fitXY"
                    android:id="@+id/postFeaturedImage"/>
    
                <com.app.customizeviews.Lato_Bold_TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="20sp"
                    android:textColor="?attr/primaryTextColor"
                    android:letterSpacing="0.02"
                    android:lineSpacingExtra="6sp"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginEnd="16dp"
                    android:id="@+id/postTitle"
                    android:layout_below="@+id/postFeaturedImage"/>
    
                <com.app.customizeviews.Lato_Regular_TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/postDate"
                    android:textColor="?attr/secondaryTextColor"
                    android:textSize="14sp"
                    android:layout_below="@+id/postTitle"
                    android:layout_marginTop="8dp"
                    android:layout_marginStart="16dp" />
    
                <WebView
                    android:id="@+id/webView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/postDate"
                    android:layout_marginTop="12dp"/>
    
                <ProgressBar
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="50dp"
                    android:id="@+id/progressBar"
                    android:layout_centerHorizontal="true"/>
    
            </RelativeLayout>
    
        </android.support.v4.widget.NestedScrollView>
    
        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            app:layout_anchorGravity="bottom"
            app:layout_anchor="@id/postDetails"
            android:elevation="25dp"
            android:background="@drawable/bottom_post_card">
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_ext_link_enabled"
                android:id="@+id/sourceLink"
                android:layout_marginStart="20dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_share_dark_article"
                android:id="@+id/postShare"
                app:layout_constraintStart_toEndOf="@id/sourceLink"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@id/postLike"/>
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_like_article_unselected"
                android:id="@+id/postLike"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintEnd_toStartOf="@id/postBookmark"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toEndOf="@id/postShare"/>
    
            <TextSwitcher
                android:id="@+id/likesCount"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toStartOf="@+id/postBookmark"
                android:clipToPadding="false"
                android:inAnimation="@anim/slide_up"
                android:outAnimation="@anim/fade_out"
                android:layout_marginEnd="5dp"
                app:layout_constraintStart_toEndOf="@id/postLike"
                app:layout_constraintBottom_toBottomOf="@id/postLike"
                app:layout_constraintTop_toTopOf="@id/postLike" />
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_bookmark_article_unselected"
                android:layout_centerVertical="true"
                android:layout_marginEnd="20dp"
                android:layout_alignParentEnd="true"
                android:id="@+id/postBookmark"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>
    
        </android.support.constraint.ConstraintLayout>
    
    </android.support.design.widget.CoordinatorLayout>

    그리고 이것은 완벽하게 작동하지만 마지막 날부터 웹 콘텐츠가 끝난 후 무한한 공백이 발생하기 시작합니다.

    여기에 이미지 설명 입력

    모든 공백은 Webview의 주요 내용 이후 Webview로 인해 발생합니다 .ViewPager를 사용하여 조각에서이 레이아웃을 열 때만 발생하지만 단일 페이지 활동이있는 레이아웃에서 열린 경우에는 발생하지 않습니다.그리고 이것은 2 ~ 3 개월에서 어제까지 완벽하게 작동하지만 어제부터는이 문제가 발생합니다.

    Webview에서 콘텐츠를로드하기위한 코드 :

    mWebView.getSettings().setLoadWithOverviewMode(true);
            mWebView.getSettings().setUseWideViewPort(true);
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.getSettings().setLoadsImagesAutomatically(true);
            mWebView.setVerticalScrollBarEnabled(false);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                WebView.setWebContentsDebuggingEnabled(true);
            }
            mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mWebView.setNestedScrollingEnabled(false);
            } else {
                mParentView.setNestedScrollingEnabled(false);
            }
     mWebView.loadDataWithBaseURL(
                                "file:///android_asset/",
                                content,
                                "text/html",
                                "utf-8",
                                null);

    답변1

    아래 코드와 같이 NestedScrollView내부의 RelativeLayout높이 속성에 wrap_content 를 사용하십시오.

      <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/postDetails"
        android:background="?attr/backgroundColor">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"> //change here
    
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"
                android:id="@+id/postFeaturedImage"/>
    
            <com.app.customizeviews.Lato_Bold_TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textColor="?attr/primaryTextColor"
                android:letterSpacing="0.02"
                android:lineSpacingExtra="6sp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="16dp"
                android:id="@+id/postTitle"
                android:layout_below="@+id/postFeaturedImage"/>
    
            <com.app.customizeviews.Lato_Regular_TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/postDate"
                android:textColor="?attr/secondaryTextColor"
                android:textSize="14sp"
                android:layout_below="@+id/postTitle"
                android:layout_marginTop="8dp"
                android:layout_marginStart="16dp" />
    
            <WebView
                android:id="@+id/webView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/postDate"
                android:layout_marginTop="12dp"/>
    
            <ProgressBar
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="50dp"
                android:id="@+id/progressBar"
                android:layout_centerHorizontal="true"/>
    
        </RelativeLayout>
    
    </android.support.v4.widget.NestedScrollView>


     

     

     

     

    출처 : https://stackoverflow.com/questions/48542412/webview-causes-infinite-scrollable-white-space

    댓글

Designed by Tistory.