Android LinearLayout внутри AppbarLayout

У меня есть appBarLayout с collapsingToolbar. Я хочу добавить linearLayout ниже collapsingToolbar, который будет прокручиваться с помощью appBarLayout. Я добавил app:layout_scrollFlags="scroll", но не работает. Я что-то упускаю или это просто невозможно?

вот код:

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_layout"
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">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/white"
            android:orientation="vertical"
            app:layout_collapseMode="none"
            app:layout_collapseParallaxMultiplier="0.3">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:scaleType="centerCrop"/>
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>
    </android.support.design.widget.CollapsingToolbarLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll">
        ...
    </LinearLayout>
</android.support.design.widget.AppBarLayout>

here's the image


person Michael Allen De Jesus    schedule 11.05.2017    source источник
comment
вы хотите, чтобы линейный макет тоже исчез или просто отображался под панелью приложений?   -  person jmarkstar    schedule 11.05.2017


Ответы (1)


Привет, Майкл, ты на правильном пути, просто немного изменись, скопируй этот код в студию и попробуй.

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_layout"
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">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/white"
            android:orientation="vertical"
            app:layout_collapseMode="none"
            app:layout_collapseParallaxMultiplier="0.3">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:scaleType="centerCrop"/>
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>

        </android.support.design.widget.CollapsingToolbarLayout>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="@dimen/activity_horizontal_margin" >
                <!-- Your content here -->
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

    </android.support.design.widget.CoordinatorLayout>

Вот пример: http://www.androidauthority.com/using-coordinatorlayout-android-apps-703720/ Надеюсь, это поможет вам.

person Rishabh Bhatia    schedule 11.05.2017
comment
спасибо, но я хочу поместить linearlayout внутри appbarlayout, потому что в конечном итоге я добавлю tablayout под этим linearlayout. Я хочу, чтобы линейный макет прокручивался с помощью панели приложений, а вкладка должна быть закреплена во время прокрутки. затем я добавлю вложенный прокрутку с другим содержимым - person Michael Allen De Jesus; 11.05.2017
comment
Это суть того, чего вы пытаетесь достичь? - person Rishabh Bhatia; 11.05.2017
comment
как бы. i.stack.imgur.com/L2Zih.png я хочу сделать что-то вроде этого . я добавлю tablayout ниже этого linearlayout - person Michael Allen De Jesus; 11.05.2017
comment
Классные ответы на stackoverflow.com/questions/33949530/ & stackoverflow.com/questions/33660591/ поможет вам? - person Rishabh Bhatia; 11.05.2017