嵌套的滚子查看滚动内容在其中,而不是在触摸工具栏布局时扩展其布局大小



在nestedscrollview中的coordinatorlayout中,我有相关性和relativelayout内部我有textView。当NestedScrollview触摸工具栏底部部分时,它将滚动文本视图内容滚动到完整的Relativelayout卡。

这是我的代码。

       <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/product_bottom_layout"
        android:fitsSystemWindows="true">
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="192dp"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="@color/white"
                app:expandedTitleTextAppearance="@style/TransparentText"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:titleEnabled="false">
                   <ImageView
                    android:id="@+id/product_img"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:adjustViewBounds="true"
                    android:fitsSystemWindows="true"
                    app:imageUrl="@{viewModel.imageUrl}"
                    android:scaleType="centerInside"
                    app:layout_collapseMode="parallax"
                    android:background="@color/white"/>
                   <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:elevation="4dp"
                    android:gravity="center_vertical"
                    android:minHeight="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:layout_scrollFlags="scroll|enterAlways"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:theme="@style/ThemeOverlay.AppCompat.Light"> 
            </android.support.v7.widget.Toolbar>
            </android.support.design.widget.CollapsingToolbarLayout>
            </android.support.design.widget.AppBarLayout>
           <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/dimen_60"
            android:layout_marginLeft="@dimen/dimen_7"
            android:layout_marginRight="@dimen/dimen_7"
            android:layout_marginTop="@dimen/dimen_7"
            android:background="@drawable/card_bg"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
               <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dimen_3"
                android:layout_marginRight="@dimen/dimen_3"
                android:layout_marginTop="@dimen/dimen_3"
                android:background="@color/white">
                <app.com.test.Views.CustomTextView
                    android:id="@+id/description_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/dimen_12"
                    android:layout_marginRight="@dimen/dimen_12"
                    android:layout_marginTop="@dimen/dimen_12"
                    android:lineSpacingExtra="8dp"
                    android:textColor="@color/title_color"
                    android:textSize="14sp"/>
                 </RelativeLayout>
             </android.support.v4.widget.NestedScrollView>
          </android.support.design.widget.CoordinatorLayout>

我得到了解决方案。它实际上是NestedScrollview不会滚动其孩子,它实际上滚动了孩子的内容,因此要滚动整个布局而不是文本,我们需要添加更多的父母布局:

           <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="fill_vertical"
            android:layout_marginBottom="@dimen/dimen_60"
            android:scrollbars="none"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/dimen_10"
                android:background="@color/bg_color"
                android:orientation="vertical"
                android:padding="@dimen/dimen_6">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/dimen_10"
                    android:layout_marginLeft="@dimen/dimen_3"
                    android:layout_marginRight="@dimen/dimen_3"
                    android:layout_marginTop="@dimen/dimen_3"
                    android:background="@drawable/card_bg">
                    <app.com.test.Views.CustomTextView
                        android:id="@+id/product_title_txt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/dimen_12"
                        android:layout_marginRight="@dimen/dimen_12"
                        android:layout_marginTop="@dimen/dimen_12"
                        android:text=""
                     />
             </RelativeLayout>
           </LinearLayout>
          </android.support.v4.widget.NestedScrollView>

最新更新