Android ScrollView не прокручивается в действии с макетом ящика

Позвольте представить вам мою деятельность:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/toolbar_actionbar"
        layout="@layout/toolbar_default"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <FrameLayout
        android:id="@+id/main_fragment_container"
        android:layout_width="match_parent"
        android:layout_below="@+id/toolbar_actionbar"
        android:layout_height="match_parent"/>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar_actionbar">

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:clickable="true"
            android:layout_height="match_parent"/>

        <!-- android:layout_marginTop="?android:attr/actionBarSize"-->
        <fragment
            android:id="@+id/fragment_drawer"
            android:name="com.package.name.navigationdrawer.NavigationDrawerFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:layout="@layout/fragment_navigation_drawer"/>
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

FrameLayout main_fragment_container — это место, где я загружаю разные фрагменты в зависимости от выбора навигационного ящика, но когда я загружаю фрагмент с помощью прокрутки ScrollView, это не работает, я вижу полосу прокрутки, когда фрагмент загружается, указывая, что только небольшой раздел находится на экране в данный момент, но никогда не будет прокручиваться. Я попробовал несколько предложений, в которых упоминалось о заключении ScrollView в LinearLayout, это не имело значения.

Я подозреваю, что навигационный ящик «перехватывает» события, которые должны достигать ScrollView, но я не знаю, что делать. Это фрагмент:

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

    <ScrollView
        android:id="@+id/fragment_who_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        android:fillViewport="true">

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

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/header_pic_s"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="17sp"
                android:text="TEEEEEST"
                android:gravity="center"
                android:padding="20dp"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

Спасибо за ваше время.

ОБНОВЛЕНИЕ: ДОБАВЬТЕ ДОПОЛНИТЕЛЬНУЮ ИНФОРМАЦИЮ:

  • Проблема здесь заключается не в ScrollView как таковом, а в том факте, что в моем макете активности DrawerLayout находится «над» ScrollView, предотвращая любые сенсорные события, достигающие ScrollView. Если я удалю DrawerLayout, ScrollView прокручивается ПРОСТО ХОРОШО.

  • Точно так же, если я поставлю ScrollView после DrawerLayout в макете активности, прокрутка будет работать нормально в ScrollView, но, конечно, DrawerLayout не работает должным образом, поскольку он должен быть поверх всего остального.

Надеюсь, я правильно объяснил себя, проверив, что я уверен в том, в чем проблема, но я не уверен, как ее исправить, мой опыт работы с Navigation Drawer ограничен, и я понятия не имею, как передать событие прокрутки. ScrollView вместо того, чтобы DrawerLayout перехватывал его.


person dbar    schedule 10.06.2015    source источник
comment
Это не решает вашу проблему, но вам не нужен родительский linearlayout вокруг вашего прокрутки. Ваш вид прокрутки должен действовать как основной вид.   -  person Thomas R.    schedule 10.06.2015
comment
Спасибо, это действительно совершенно ненужно, и я просто удалил его. Я попробовал это только потому, что это было дано здесь в качестве ответа при проблемах с прокруткой ScrollViews.   -  person dbar    schedule 10.06.2015
comment
Нет проблем :) Почему ваш фрейм (контейнер) кликабельный? Сюда вы добавляете свой контент? Попробуйте убрать этот флаг.   -  person Thomas R.    schedule 10.06.2015
comment
Этот FrameLayout — это не то место, куда я загружаю свои фрагменты. «Контейнер» FrameLayout является частью NavigationDrawer, и эта часть прекрасно работает. Именно FrameLayout 'main_fragment_container' будет заменен в этом случае не прокручиваемым ScrollView.   -  person dbar    schedule 10.06.2015
comment
Я добавил дополнительную информацию к вопросу.   -  person dbar    schedule 10.06.2015
comment
Ах хорошо. Я думаю, что все элементы должны быть в вашем DrawerLayout, это должно быть корнем всего.   -  person Thomas R.    schedule 10.06.2015


Ответы (4)


Вы должны переместить макет фрейма с идентификатором «main_fragment_container» внутри макета ящика следующим образом:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
    android:id="@+id/toolbar_actionbar"
    layout="@layout/toolbar_default"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar_actionbar">

    <FrameLayout
        android:id="@+id/main_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar_actionbar" />

    <!-- android:layout_marginTop="?android:attr/actionBarSize"-->
    <fragment
        android:id="@+id/navigation_drawer"
        android:name="vodafone.navdrawertest.NavigationDrawerFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>

person Ahmed Talaat    schedule 10.06.2015
comment
Я дам это как правильный ответ. Я также ответил на свой вопрос этим решением (которое работает). Спасибо! (особенно Томасу за то, что он помог мне найти это решение самостоятельно) - person dbar; 10.06.2015
comment
Я использовал это, но я все еще не могу прокрутить свой ящик. Нужно ли иметь RelativeLayout перед DrawerLayout? - person Kairi San; 01.12.2015

Попробуйте изменить порядок макета:

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent“>

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

        <include
            android:id="@+id/toolbar_actionbar"
            layout="@layout/toolbar_default"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <FrameLayout
            android:id="@+id/main_fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </LinearLayout>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</FrameLayout>

<!-- android:layout_marginTop="?android:attr/actionBarSize"-->
<fragment
    android:id="@+id/fragment_drawer"
    android:name="com.ulusol.knowmyshop.navigationdrawer.NavigationDrawerFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:layout="@layout/fragment_navigation_drawer"/>

</android.support.v4.widget.DrawerLayout>
person Thomas R.    schedule 10.06.2015
comment
Спасибо, но этот макет портит все в плане структуры и не дает мне ни прокрутки, ни навигационного ящика. - person dbar; 10.06.2015
comment
Хотя я не могу назвать это правильным решением, это помогло мне исправить макет. Мой FrameLayout действительно должен заходить внутрь DrawerLayout, чтобы его можно было прокручивать. - person dbar; 10.06.2015
comment
Я снова заказал его. Но я не знаю, как «контейнер» оказывается на месте. В конце концов, это помогло найти вам правильный ответ :) - person Thomas R.; 10.06.2015

Спасибо Томасу за то, что он помог мне найти ответ.

FrameLayout, в котором находится ScrollView, должен находиться внутри DrawerLayout, чтобы его можно было прокручивать. Я также отказался от другого макета контейнера, потому что он не использовался. Вот как остается активность:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/toolbar_actionbar"
        layout="@layout/toolbar_default"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar_actionbar">

        <FrameLayout
            android:id="@+id/main_fragment_container"
            android:layout_width="match_parent"
            android:layout_below="@+id/toolbar_actionbar"
            android:layout_height="match_parent"/>

        <!-- android:layout_marginTop="?android:attr/actionBarSize"-->
        <fragment
            android:id="@+id/fragment_drawer"
            android:name="com.package.name.navigationdrawer.NavigationDrawerFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:layout="@layout/fragment_navigation_drawer"/>
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>
person dbar    schedule 10.06.2015

Попробуйте добавить следующее поведение в родительский макет:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

У меня была почти аналогичная проблема в AppBarLayout, которая находится в DrawerLayout. Это может сработать.

person Avik Chowdhury    schedule 21.06.2018