NestedScrollView не прокручивает.View.canScrollVertically () возвращает false - PullRequest
0 голосов
/ 01 февраля 2019

В моем приложении для Android у меня есть BottomSheetDialogFragment, который содержит NestedScrollView, внутри которого есть пользовательский класс ImageView с измененным onMeasure().

Когда я пробую код в независимом приложении в Activity, NestedScrollView прокручивается правильно.

Но когда я интегрирую тот же код в BottomSheetDialogFragment моего приложения, он не прокручивается иcanScrollVertically() (как -1, так и 1) возвращает false для NestedScrollView.

Я установил видимость 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>

AspectRatioImageView.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);
}
}

1 Ответ

0 голосов
/ 19 февраля 2019

Ошибка была BottomSheetDialogFragment . Может быть размещен только один ребенок с nestedScrolling.В моем случае я добавил WebView и NestedScrollViewImageView внутри).

Таким образом, независимо от того, установил ли я видимость View.GONE для WebView дочерний элемент прокрутки для BottomSheetDialogFragment всегда был установлен на WebView.

Нижняя строка.Я закончил тем, что создал отдельный BottomSheetDialogFragment для ImageView, поскольку BottomSheetDialogFragment принимает только один дочерний элемент прокрутки (самый первый, который он находит при сканировании из иерархии верхних частей представления).

Теперь все работает нормально.

...