NestedScrollView не отображается внутри CoordinatorLayout

У меня есть CoordinatorLayout с NestedScrollView и CollapsingToolbarLayout. Я помещаю все внутрь CollapsingToolbarLayout, которое я хочу сначала отобразить на экране, затем добавляю NestedScrollView, чтобы показать больше контента, но NestedScrollView не отображается на экране.

Вот мой XML-макет

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true"
    android:clipToPadding="false"
    android:background="?android:attr/colorBackground"
    android:id="@+id/viewuserProfileMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <RelativeLayout
                android:id="@+id/relativeParent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <ImageView
                    android:id="@+id/upCoverPhoto"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/redName"/>


                <!--PUT TOOLBAR HERE-->
                <RelativeLayout
                    android:id="@+id/upDetails"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/diagonal_cut_layerlist"
                    android:elevation="12dp"
                    android:translationZ="12dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="115dp">
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="115dp"
                        android:layout_marginRight="10dp"
                        android:gravity="end"
                        android:orientation="horizontal">
                        <Button
                            android:id="@+id/Button_FollowFriends"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            style="@style/AppButton"
                            android:text="Follow"
                            />

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

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:id="@+id/profilePicture_Cut"
                            android:layout_width="80dp"
                            android:layout_height="80dp"
                            android:src="@drawable/baby"
                            app:civ_border_width="2dp"
                            app:civ_border_color="@color/primary"
                            android:layout_marginTop="85dp"
                            android:layout_marginLeft="15dp"/>
                        <TextView
                            android:id="@+id/upUserName"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColor="@color/secondary_text"
                            android:layout_marginTop="10dp"
                            android:textSize="28sp"
                            android:layout_marginLeft="10dp"
                            android:text="Susan Ledger"/>

                        <TextView
                            android:id="@+id/upUserCity"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:drawableLeft="@drawable/home"
                            android:drawablePadding="5dp"
                            android:layout_marginTop="5dp"
                            android:layout_marginLeft="10dp"
                            android:textSize="18sp"
                            android:textColor="@color/secondary_text"
                            android:text="Delhi,India"/>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="15dp"
                            android:gravity="center"
                            android:orientation="horizontal"
                            android:weightSum="3">
                            <Button
                                android:id="@+id/Button_AddFriend"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                style="@style/AppButton"
                                android:text="Add Friend"
                                android:layout_weight="1"/>

                            <Button
                                android:id="@+id/Button_RejectRequest"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                style="@style/AppButton"
                                android:text="Reject"
                                android:layout_weight="1"/>

                            <Button
                                android:id="@+id/Button_MessageFriend"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                style="@style/AppButton"
                                android:text="Message"
                                android:layout_weight="1"/>



                        </LinearLayout>

                    </LinearLayout>



                </RelativeLayout>
            </RelativeLayout>

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


    <android.support.v4.widget.NestedScrollView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/up_NestedScrollView"
        android:fillViewport="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">



        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            >

            <!--To show tab on top of view pager-->
            <android.support.design.widget.TabLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabMode="scrollable"
                app:tabTextColor="@color/place_autocomplete_prediction_primary_text_highlight"
                app:tabSelectedTextColor="@color/primary_text"
                app:tabIndicatorColor="@color/primary_light"
                android:id="@+id/up_Viewpager_Tab">
            </android.support.design.widget.TabLayout>
            <android.support.v4.view.ViewPager
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/userProfile_Viewpager_Tab"
                android:id="@+id/up_Viewpager_ViewPager">

            </android.support.v4.view.ViewPager>



        </RelativeLayout>

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

person androidXP    schedule 06.07.2018    source источник


Ответы (2)


Дайте wrap_content в высоту вашего AppBarLayout

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

А также

   `android:fitsSystemWindows="false"
    app:contentScrim="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"`

эти строки к вашему CollapsingToolbarLayout

person Aaditya Brahmbhatt    schedule 06.07.2018
comment
если я помещу wrap_content в AppBarLayout, тогда он сожмет весь контент, но я хочу, чтобы он помещался на весь экран. - person androidXP; 06.07.2018
comment
@androidXP, тогда как у вас может быть два макета на одном экране? - person Aaditya Brahmbhatt; 06.07.2018
comment
даже после вложенного отображения wrap_content, но без прокрутки - person androidXP; 06.07.2018
comment
@androidXP попробуйте добавить android:fitsSystemWindows="false" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|enterAlways" эти строки в свой CollapsingToolbarLayout - person Aaditya Brahmbhatt; 06.07.2018
comment
он работает, но мое круглое изображение не закреплено на панели инструментов, вы можете помочь в этом? - person androidXP; 06.07.2018

попробуй дай

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:fitsSystemWindows="true">

Потому что AppBar не может быть match_parent

person Abdugani_T    schedule 06.07.2018
comment
В настоящее время мой AppBar - это match_parent, и он работает нормально. - person androidXP; 06.07.2018