Как использовать NestedScrollView

В моем приложении я хочу использовать NestedScrollView в DrawerLayout.
И для этого я пишу ниже код.
Я хочу показать FAB внизу макета, но покажите мне под карточкой!
Я не хочу показывать внизу карточки, я хочу показывать нижнюю часть макета!
Пожалуйста, посмотрите на изображение ниже, чтобы понять, что я имею в виду:

введите здесь описание изображения

Мои коды:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/toNightDrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="end">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

                <RelativeLayout
                    android:id="@+id/reviewSerialFrag_newsCommentsLay"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="visible">

                    <android.support.v7.widget.CardView
                        android:id="@+id/reviewSerialFrag_newsCommentsCard"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/padding8"
                        ads:cardBackgroundColor="@android:color/white"
                        ads:cardElevation="@dimen/size2"
                        app:contentPadding="@dimen/padding8">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">

                            <RelativeLayout
                                android:id="@+id/reviewSerialFrag_newsCommentsHeaderLay"
                                android:layout_width="match_parent"
                                android:layout_height="@dimen/size50">

                                <ImageView
                                    android:id="@+id/reviewSerialFrag_newsCommentsHeaderImage"
                                    android:layout_width="@dimen/size35"
                                    android:layout_height="@dimen/size35"
                                    android:layout_centerVertical="true"
                                    android:alpha="0.8"
                                    android:src="@drawable/ic_comments"
                                    android:tint="@color/darkBlueGrey" />

                                <TextView
                                    android:id="@+id/reviewSerialFrag_newsCommentsUserTypeText"
                                    android:layout_width="wrap_content"
                                    android:layout_height="match_parent"
                                    android:layout_margin="@dimen/padding10"
                                    android:layout_toRightOf="@+id/reviewSerialFrag_newsCommentsHeaderImage"
                                    android:fontFamily="sans-serif-light"
                                    android:gravity="center_vertical"
                                    android:textColor="@color/darkBlueGrey"
                                    android:textSize="@dimen/font16" />

                                <TextView
                                    android:id="@+id/reviewSerialFrag_newsCommentsReviewTypeText"
                                    android:layout_width="wrap_content"
                                    android:layout_height="match_parent"
                                    android:layout_margin="@dimen/padding10"
                                    android:layout_toRightOf="@+id/reviewSerialFrag_newsCommentsUserTypeText"
                                    android:fontFamily="sans-serif-light"
                                    android:gravity="center_vertical"
                                    android:textColor="@color/darkBlueGrey"
                                    android:textSize="@dimen/font14" />

                            </RelativeLayout>

                            <android.support.v7.widget.RecyclerView
                                android:id="@+id/reviewSerialFrag_newsCommentsRecyclerView"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/reviewSerialFrag_newsCommentsHeaderLay"
                                android:layout_marginTop="@dimen/padding5" />

                        </RelativeLayout>

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

                </RelativeLayout>
                <!--EmptyList-->
                <RelativeLayout
                    android:id="@+id/reviewSerialFrag_EmptyLsy"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="gone">

                    <include layout="@layout/empty_list" />

                </RelativeLayout>

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/reviewSerialFrag_FilterBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_margin="@dimen/padding15"
                android:src="@drawable/ic_filter"
                app:fabSize="normal" />

        </RelativeLayout>

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

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

Как я могу решить эту проблему?


person Community    schedule 27.07.2017    source источник


Ответы (3)


Эй, мужик, попробуй этот код:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/toNightDrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="end">

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

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

                <RelativeLayout
                    android:id="@+id/reviewSerialFrag_newsCommentsLay"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="visible">

                    <android.support.v7.widget.CardView
                        android:id="@+id/reviewSerialFrag_newsCommentsCard"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/padding8"
                        ads:cardBackgroundColor="@android:color/white"
                        ads:cardElevation="@dimen/size2"
                        app:contentPadding="@dimen/padding8">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">

                            <RelativeLayout
                                android:id="@+id/reviewSerialFrag_newsCommentsHeaderLay"
                                android:layout_width="match_parent"
                                android:layout_height="@dimen/size50">

                                <ImageView
                                    android:id="@+id/reviewSerialFrag_newsCommentsHeaderImage"
                                    android:layout_width="@dimen/size35"
                                    android:layout_height="@dimen/size35"
                                    android:layout_centerVertical="true"
                                    android:alpha="0.8"
                                    android:src="@drawable/ic_comments"
                                    android:tint="@color/darkBlueGrey" />

                                <TextView
                                    android:id="@+id/reviewSerialFrag_newsCommentsUserTypeText"
                                    android:layout_width="wrap_content"
                                    android:layout_height="match_parent"
                                    android:layout_margin="@dimen/padding10"
                                    android:layout_toRightOf="@+id/reviewSerialFrag_newsCommentsHeaderImage"
                                    android:fontFamily="sans-serif-light"
                                    android:gravity="center_vertical"
                                    android:textColor="@color/darkBlueGrey"
                                    android:textSize="@dimen/font16" />

                                <TextView
                                    android:id="@+id/reviewSerialFrag_newsCommentsReviewTypeText"
                                    android:layout_width="wrap_content"
                                    android:layout_height="match_parent"
                                    android:layout_margin="@dimen/padding10"
                                    android:layout_toRightOf="@+id/reviewSerialFrag_newsCommentsUserTypeText"
                                    android:fontFamily="sans-serif-light"
                                    android:gravity="center_vertical"
                                    android:textColor="@color/darkBlueGrey"
                                    android:textSize="@dimen/font14" />

                            </RelativeLayout>

                            <android.support.v7.widget.RecyclerView
                                android:id="@+id/reviewSerialFrag_newsCommentsRecyclerView"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/reviewSerialFrag_newsCommentsHeaderLay"
                                android:layout_marginTop="@dimen/padding5" />

                        </RelativeLayout>

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

                </RelativeLayout>
                <!--EmptyList-->
                <RelativeLayout
                    android:id="@+id/reviewSerialFrag_EmptyLsy"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="gone">

                    <include layout="@layout/empty_list" />

                </RelativeLayout>

            </RelativeLayout>

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

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/reviewSerialFrag_FilterBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_margin="@dimen/padding15"
            android:src="@drawable/ic_filter"
            app:fabSize="normal" />

    </RelativeLayout>

</android.support.v4.widget.DrawerLayout>
person Mohammad Nouri    schedule 27.07.2017

Итак, попробуйте сделать это:

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/toNightDrawerLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:openDrawer="end">

    <android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

                <RelativeLayout
                    android:id="@+id/reviewSerialFrag_newsCommentsLay"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="visible">

                    <android.support.v7.widget.CardView
                        android:id="@+id/reviewSerialFrag_newsCommentsCard"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/padding8"
                        ads:cardBackgroundColor="@android:color/white"
                        ads:cardElevation="@dimen/size2"
                        app:contentPadding="@dimen/padding8">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">

                            <RelativeLayout
                                android:id="@+id/reviewSerialFrag_newsCommentsHeaderLay"
                                android:layout_width="match_parent"
                                android:layout_height="@dimen/size50">

                                <ImageView
                                    android:id="@+id/reviewSerialFrag_newsCommentsHeaderImage"
                                    android:layout_width="@dimen/size35"
                                    android:layout_height="@dimen/size35"
                                    android:layout_centerVertical="true"
                                    android:alpha="0.8"
                                    android:src="@drawable/ic_comments"
                                    android:tint="@color/darkBlueGrey" />

                                <TextView
                                    android:id="@+id/reviewSerialFrag_newsCommentsUserTypeText"
                                    android:layout_width="wrap_content"
                                    android:layout_height="match_parent"
                                    android:layout_margin="@dimen/padding10"
                                    android:layout_toRightOf="@+id/reviewSerialFrag_newsCommentsHeaderImage"
                                    android:fontFamily="sans-serif-light"
                                    android:gravity="center_vertical"
                                    android:textColor="@color/darkBlueGrey"
                                    android:textSize="@dimen/font16" />

                                <TextView
                                    android:id="@+id/reviewSerialFrag_newsCommentsReviewTypeText"
                                    android:layout_width="wrap_content"
                                    android:layout_height="match_parent"
                                    android:layout_margin="@dimen/padding10"
                                    android:layout_toRightOf="@+id/reviewSerialFrag_newsCommentsUserTypeText"
                                    android:fontFamily="sans-serif-light"
                                    android:gravity="center_vertical"
                                    android:textColor="@color/darkBlueGrey"
                                    android:textSize="@dimen/font14" />

                            </RelativeLayout>

                            <android.support.v7.widget.RecyclerView
                                android:id="@+id/reviewSerialFrag_newsCommentsRecyclerView"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/reviewSerialFrag_newsCommentsHeaderLay"
                                android:layout_marginTop="@dimen/padding5" />

                        </RelativeLayout>

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

                </RelativeLayout>
                <!--EmptyList-->
                <RelativeLayout
                    android:id="@+id/reviewSerialFrag_EmptyLsy"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="gone">

                    <include layout="@layout/empty_list" />

                </RelativeLayout>

        </RelativeLayout>

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

     <android.support.design.widget.FloatingActionButton
                android:id="@+id/reviewSerialFrag_FilterBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end|bottom"
                android:layout_margin="@dimen/padding15"
                android:src="@drawable/ic_filter"
                app:fabSize="normal" />

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

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

Установите все контексты внутри макета координатора и потрясающие вне вложенного прокрутки. Если не работает, попросите меня отправить другим возможным способом.

person Bruno Ferreira    schedule 27.07.2017
comment
@ Кир, нет проблем :) - person Bruno Ferreira; 27.07.2017

  <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/Widget.AppTheme.AppBarOverlay">

    <include
        layout="@layout/include_layout_toolbar_scroll"/>

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


 <include layout="@layout/include_layout_content_with_nestedscroll"/>

 <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_task_accept"
    android:layout_width="wrap_content"
     android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
     android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_accepted"
     app:layout_behavior="pass.to.FabScrollBehavior.Class"
    app:theme="@style/Widget.AppTheme.Fab"/>

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

use coordinatorlayout

используйте эту ссылку

person Hamid.Waezi    schedule 27.07.2017
comment
Я могу использовать в CoordinatorLayout , но у меня проблемы с приведенными выше кодами! пожалуйста, помогите мне с моими вышеуказанными кодами, мой друг - person ; 27.07.2017
comment
эй @hamid.Waezi, вы используете CoordinatorLayout, но выше вопрос с NestedScrollView. для использования FAB в NestedScrollView вы используете мой приведенный ниже код. я надеюсь помочь вам - person Mohammad Nouri; 27.07.2017