When using the CoordinatorLayout my ScrollView has an incorrect size

前端 未结 2 2068
时光取名叫无心
时光取名叫无心 2020-12-15 02:41

I\'m using a ScrollView in a layout, and am attempting to use the new CoordinatorLayout from the design support library.

My layout file looks like this:

<         


        
相关标签:
2条回答
  • 2020-12-15 03:25

    The standard ScrollView is only meant to be used as a parent. You need to change the ScrollView to a android.support.v4.widget.NestedScrollView.

    An example can be seen in the reference documentation for AppBarLayout.

    0 讨论(0)
  • 2020-12-15 03:35

    NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.

    You can use a NestedScrollView within a parent ScrollView. NestedScrollView is used when there is a need for a scrolling view inside another scrolling view. This is where it is useful, when the system needs to decide which view to scroll.

    Here is an example of NestedScrollView with CoordinatorLayout:

     <android.support.design.widget.CoordinatorLayout
             xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto"
             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"
                 app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
             <!-- Your scrolling content -->
    
         </android.support.v4.widget.NestedScrollView>
    
         <android.support.design.widget.AppBarLayout
                 android:layout_height="wrap_content"
                 android:layout_width="match_parent">
    
             <android.support.v7.widget.Toolbar
                     ...
                     app:layout_scrollFlags="scroll|enterAlways"/>
    
             <android.support.design.widget.TabLayout
                     ...
                     app:layout_scrollFlags="scroll|enterAlways"/>
    
         </android.support.design.widget.AppBarLayout>
    
     </android.support.design.widget.CoordinatorLayout>
    
    0 讨论(0)
提交回复
热议问题