Сделать панель инструментов в NestedScrollView недоступной для прокрутки - PullRequest
0 голосов
/ 02 ноября 2018

У меня есть пользовательский Toolbar внутри NestedScrollView. В NestedScrollView есть также некоторые TextViews и Edittexts.

Моя проблема в том, что прокручиваются не только TextViews и Edittexts, но и Toolbar.

Логично, что Toolbar в NestedScrollView прокручивается.

Я хочу пользовательский Toolbar с абсолютной позицией вверху и возможностью прокрутки TextViews и Edittexts.

Это код, над которым я работаю:

<android.support.v4.widget.NestedScrollView
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

 <android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="#ffffff"
    android:elevation="5dp"
    android:minHeight="?attr/actionBarSize"
    app:contentInsetEnd="50dp"
    app:contentInsetRight="50dp"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetStartWithNavigation="0dp"
    app:popupTheme="@style/AppTheme.PopupOverlay">

  </android.support.v7.widget.Toolbar>

  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="A long unimportant text"/>

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

Поэтому я попытался обернуть только TextViews и Edittexts в ScrollView, например:

        <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#ffffff"
            android:elevation="5dp"
            android:minHeight="?attr/actionBarSize"
            app:contentInsetEnd="50dp"
            app:contentInsetRight="50dp"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp"
            app:popupTheme="@style/AppTheme.PopupOverlay">
            </android.support.v7.widget.Toolbar>

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="A long unimportant text"/>

                </ScrollView>

        </LinearLayout>

Но это не работает.

Это очень важно использовать custom Toolbar.

Ответы [ 2 ]

0 голосов
/ 03 ноября 2018

ScrollViewNestedScrollView) позволят разрешить добавление к ним нескольких прямых детей, но для их правильной работы у них должен быть ровно один прямой ребенок. Итак, оберните содержимое вашего ScrollView в wrap_content LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="A long unimportant text"/>

            <!-- many more views -->

        </LinearLayout>

    </ScrollView>

</LinearLayout>
0 голосов
/ 03 ноября 2018

Попробуйте относительный макет

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".EmptyActivity">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#ffffff"
        android:elevation="5dp"
        android:minHeight="?attr/actionBarSize"
        app:contentInsetEnd="50dp"
        app:contentInsetLeft="0dp"
        app:contentInsetRight="50dp"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="A long unimportant text" />

    </ScrollView>

</RelativeLayout>
...