如何使用NestedScrollView

问题描述 投票:1回答:3

在我的应用程序中,我想使用NestedScrollView进入DrawerLayout。 为此我写下面的代码。 我想在布局底部显示FAB,但是在卡片下方显示我! 我不想在卡片的下面显示,我想显示布局的底部! 请参见下图,了解我的意思:

enter image description here

我的代码:

<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>

我该如何解决这个问题?

android android-layout floating-action-button
3个回答
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>

0
投票

所以尝试这样做:

    <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>

在协调器布局中设置所有的竞争,并在nestedscrollview之外设置。如果不工作,请让我发送其他可能的方式。


0
投票

  <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>

使用coordinatorlayout

使用这个link

© www.soinside.com 2019 - 2024. All rights reserved.