NestedScrollView不会滚动。 View.canScrollVertically()返回false

问题描述 投票:0回答:1

在我的Android应用程序中,我有一个BottomSheetDialogFragment,其中包含一个NestedScrollView,其中有一个自定义类ImageViewonMeasure()更改。

当我在Activity的独立应用程序中尝试代码时,NestedScrollView正确滚动。

但是当我在我的应用程序的BottomSheetDialogFragment中集成相同的代码时,它不会滚动而且canScrollVertically()(-1和1)对NestedScrollView返回false。

当我需要展示content_webview时,我将View.GONE的可见性设置为NestedScrollView,将View.VISIBLE的可见性设置为ImageView。图像形成并正确加载。问题是NestedScrollView不滚动。

我的layout文件有什么问题?我没有禁用java文件中任何类型的滚动。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="false"
android:background="@color/transparent"
android:focusableInTouchMode="true"
android:clickable="true"
android:focusable="true">


<ProgressBar
    android:id="@+id/progress_webview_loading"
    android:layout_width="match_parent"
    android:layout_height="2.5dp"
    android:indeterminate="false"
    android:progressTint="@color/green"
    android:backgroundTint="@color/lighter_gray_2"
    android:max="100"
    style="?android:attr/progressBarStyleHorizontal"
    />

<com.hootout.webviews.NestedScrollingWebView
    android:id="@+id/content_webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/progress_webview_loading">

</com.hootout.webviews.NestedScrollingWebView>

<android.support.v4.widget.NestedScrollView
    android:id="@+id/pdf_view_scroller"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/progress_webview_loading"
    android:isScrollContainer="true"
    android:visibility="gone">

    <com.hootout.custom.AspectRatioImageView
        android:id="@+id/pdf_image_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        />

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

<TextView
    android:id="@+id/btn_close_content_webview"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:text="@string/icon_close_without_circle"
    android:textColor="@color/green"
    android:gravity="center"
    android:shadowColor="@color/black"
    android:shadowDx="1"
    android:shadowDy="1"
    android:shadowRadius="5"
    android:background="@drawable/round_button_goto_top"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="10dp"
    />


</RelativeLayout>

aspect ratio image view.Java

import android.content.Context;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;

public class AspectRatioImageView extends AppCompatImageView {

public AspectRatioImageView(Context context) {
    super(context);
}

public AspectRatioImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public AspectRatioImageView(Context context, AttributeSet attrs, int 
defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = 0;
    int height = 0;
    if(getDrawable() != null)
    {
        width = MeasureSpec.getSize(widthMeasureSpec);
        height = width * getDrawable().getIntrinsicHeight() / 
getDrawable().getIntrinsicWidth();
    }
    else{
        width = MeasureSpec.getSize(widthMeasureSpec);
        height = MeasureSpec.getSize(heightMeasureSpec);
    }
    setMeasuredDimension(width, height);
}
}
android android-nestedscrollview
1个回答
0
投票

问题是BottomSheetDialogFragment只能容纳一个孩子与nestedScrolling。在我的情况下,我添加WebViewNestedScrollView(里面有ImageView)。

因此,无论我是否为View.GONE设置可见性WebViewBottomSheetDialogFragment的滚动子项始终设置为WebView

底线。我最终为BottomSheetDialogFragment创建了一个单独的ImageView,因为BottomSheetDialogFragment只接受一个滚动子项(从视图层次结构顶部扫描时找到的第一个)。

现在一切正常。

© www.soinside.com 2019 - 2024. All rights reserved.